//: C07:UniqueList.cpp // From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison. // (c) 1995-2004 MindView, Inc. All Rights Reserved. // See source code use permissions stated in the file 'License.txt', // distributed with the code package available at www.MindView.net. // Testing list's unique() function. #include #include #include using namespace std; int a[] = { 1, 3, 1, 4, 1, 5, 1, 6, 1 }; const int ASZ = sizeof a / sizeof *a; int main() { // For output: ostream_iterator out(cout, " "); list li(a, a + ASZ); li.unique(); // Oops! No duplicates removed: copy(li.begin(), li.end(), out); cout << endl; // Must sort it first: li.sort(); copy(li.begin(), li.end(), out); cout << endl; // Now unique() will have an effect: li.unique(); copy(li.begin(), li.end(), out); cout << endl; } ///:~