text cover

Data Abstraction and Problem Solving with C++

Walls and Mirrors

by Frank M. Carrano

Addison Wesley Logo

example368.cpp

Go to the documentation of this file.
00001 
00015 #include <iostream>
00016 #include <list>
00017 #include <queue>
00018 #include <stack>
00019 using namespace std;
00020 
00021 int main()
00022 {
00023    list<int> myList;  // create an empty list
00024    list<int>::iterator i = myList.begin();
00025 
00026    for (int j = 1; j < 5; j++)
00027    {  i = myList.insert(i, j);
00028       i++;
00029    }  // end for
00030 
00031    cout << "myList:  ";
00032    i = myList.begin();
00033    while (i != myList.end())
00034    {  cout << *i << " ";
00035       i++;
00036    }  // end while
00037    cout << endl;
00038 
00039    // assumes the front of the list is the front of the
00040    // queue
00041    queue<int, list<int> > myQueue(myList);
00042 
00043    // assumes the back of the list is the top of the stack
00044    stack<int, list<int> > myStack(myList);
00045 
00046    cout << "myQueue: ";
00047    while (!myQueue.empty())
00048    {  cout << myQueue.front() << " ";
00049       myQueue.pop();
00050    }  // end while
00051    cout << endl;
00052 
00053    cout << "myStack: ";
00054    while (!myStack.empty())
00055    {  cout << myStack.top() << " ";
00056       myStack.pop();
00057    }  // end while
00058    cout << endl;
00059    return 0;
00060 }  // end main

Generated on Sun Aug 27 17:19:54 2006 for AWLogo by  doxygen 1.4.6