![]() |
Data Abstraction and Problem Solving with C++Walls and Mirrorsby Frank M. Carrano |
![]() |
example231.cppGo to the documentation of this file.00001 00016 list<int> myList; 00017 list<int>::iterator curr; 00018 00019 // right now, the list is empty; 00020 // start the iterator at the beginning of myList 00021 curr = myList.begin(); 00022 // test for empty list 00023 if (curr == myList.end()) 00024 cout << "The list is empty" << endl; 00025 00026 // insert five items into the list myList 00027 for (int j = 0; j < 5; j++) 00028 // places item j at the front of the list 00029 curr = myList.insert(curr, j); 00030 00031 // now output each item in the list starting with the 00032 // first item in the list; keep moving the iterator 00033 // to the next item in the list until the end of 00034 // the list is reached 00035 for (curr = myList.begin(); curr != myList.end(); curr++) 00036 cout << *curr << " "; 00037 cout << endl; |