// File: ListEx2.cpp // Quick list example with iterator #include // C++ I/O routines #include // The STL list class using namespace std; int main () { // Create a new, empty linked list of int. list x; // Insert two items at the front of this list. x.push_front(5); x.push_front(3); // Insert an item at the end of the list. x.push_back(4); // Show all of the items now in the list. list::iterator i; for (i = x.begin(); i != x.end(); i++) { printf("%d - ", *i); } printf("\n"); // Find the element with the value 5. bool found = false; i = x.begin(); while (!found && (i != x.end())) { if (*i == 5) { found = true; } else { i++; } } // If the 5 was found, delete it from the list. if (found) { x.erase(i); } // Show the list again. for (i = x.begin(); i != x.end(); i++) { printf("%d - ", *i); } printf("\n"); return 0; }