home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C20 / ListStability.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  1.0 KB  |  38 lines

  1. //: C20:ListStability.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Things don't move around in lists
  7. #include "Noisy.h"
  8. #include <list>
  9. #include <iostream>
  10. #include <algorithm>
  11. using namespace std;
  12.  
  13. int main() {
  14.   list<Noisy> l;
  15.   ostream_iterator<Noisy> out(cout, " ");
  16.   generate_n(back_inserter(l), 25, NoisyGen());
  17.   cout << "\n Printing the list:" << endl;
  18.   copy(l.begin(), l.end(), out);
  19.   cout << "\n Reversing the list:" << endl;
  20.   l.reverse();
  21.   copy(l.begin(), l.end(), out);
  22.   cout << "\n Sorting the list:" << endl;
  23.   l.sort();
  24.   copy(l.begin(), l.end(), out);
  25.   cout << "\n Swapping two elements:" << endl;
  26.   list<Noisy>::iterator it1, it2;
  27.   it1 = it2 = l.begin();
  28.   it2++;
  29.   swap(*it1, *it2);
  30.   cout << endl;
  31.   copy(l.begin(), l.end(), out);
  32.   cout << "\n Using generic reverse(): " << endl;
  33.   reverse(l.begin(), l.end());
  34.   cout << endl;
  35.   copy(l.begin(), l.end(), out);
  36.   cout << "\n Cleanup" << endl;
  37. } ///:~
  38.