// test_algorithms.cpp not exhaustive, just some functions #include #include #include using namespace std; static int pos_nums() { static int i=1; return i++; } // 1, 2, 3, ... void put(int i) { cout << ' ' << i; } // put int with a leading space int main() { vector a(10); cout << "test_algorithms.cpp running on size"; put(a.size()); cout << endl; generate(a.begin(), a.end(), pos_nums); // pos_mums generates values cout << "generate "; for_each(a.begin(), a.end(), put); // print values cout << endl; random_shuffle(a.begin(), a.end()); // shuffle cout << "randomized "; for_each(a.begin(), a.end(), put); cout << endl; sort(a.begin(), a.end()); // sort cout << "sorted "; for_each(a.begin(), a.end(), put); cout << endl; reverse(a.begin(), a.end()); // reverse order cout << "reversed "; for_each(a.begin(), a.end(), put); cout << endl; return 0; }