CHAPTER5-12.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
源码类别:

STL

开发平台:

C/C++

  1. //文件名:CHAPTER5-12.cpp
  2. #include <list>
  3. #include <iostream>
  4. #include <queue>
  5. #include <deque>
  6. using namespace std ;
  7. // 通过list使用queue 
  8. typedef list<int > INTLIST;
  9. typedef queue<int>  INTQUEUE;
  10. //通过deque使用queue 
  11. typedef deque<char*> CHARDEQUE;
  12. typedef queue<char*> CHARQUEUE;
  13. void main(void)
  14. {
  15.     int size_q;
  16.     INTQUEUE q;
  17.     CHARQUEUE p;
  18.     // Insert items in the queue(uses list)
  19.     q.push(42);
  20.     q.push(100);
  21.     q.push(49);
  22.     q.push(201);
  23.     // Output the size of queue
  24.     size_q = q.size();
  25.     cout << "size of q is:" << size_q << endl;
  26.     // Output items in queue using front()
  27.     // and use pop() to get to next item until
  28.     // queue is empty
  29.     while (!q.empty())    {    cout << q.front() << endl;   q.pop();   }
  30. // Insert items in the queue(uses deque)
  31.     p.push("cat");
  32.     p.push("ape");
  33.     p.push("dog");
  34.     p.push("mouse");
  35.     p.push("horse");
  36.     // Output the item inserted last using back()
  37.     cout << p.back() << endl;
  38.     // Output the size of queue
  39.     size_q = p.size();
  40.     cout << "size of p is:" << size_q << endl;
  41.     // Output items in queue using front()
  42.     // and use pop() to get to next item until
  43.     // queue is empty
  44.     while (!p.empty())  {  cout << p.front() << endl;  p.pop(); }
  45. }