//: C04:ListStability.cpp // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt // Things don't move around in lists #include "Noisy.h" #include #include #include using namespace std; int main() { list l; ostream_iterator out(cout, " "); generate_n(back_inserter(l), 25, NoisyGen()); cout << "\n Printing the list:" << endl; copy(l.begin(), l.end(), out); cout << "\n Reversing the list:" << endl; l.reverse(); copy(l.begin(), l.end(), out); cout << "\n Sorting the list:" << endl; l.sort(); copy(l.begin(), l.end(), out); cout << "\n Swapping two elements:" << endl; list::iterator it1, it2; it1 = it2 = l.begin(); it2++; swap(*it1, *it2); cout << endl; copy(l.begin(), l.end(), out); cout << "\n Using generic reverse(): " << endl; reverse(l.begin(), l.end()); cout << endl; copy(l.begin(), l.end(), out); cout << "\n Cleanup" << endl; } ///:~