码迷,mamicode.com
首页 > 其他好文 > 详细

第19章 queue队列容器

时间:2014-11-21 01:13:17      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   os   sp   strong   on   div   

 

 

/*

  第19章 queue队列容器
   19.1 queue技术原理
   19.2 queue应用基础
   19.3 本章小结
*/



//  第19章 queue队列容器
//   19.1 queue技术原理
//   19.2 queue应用基础 -------------------------------------------------------------------------------------------


//273
#include <queue>
#include <iostream>
int main(void)
{
  using namespace std;
  //创建queue对象
  queue < int > q;
  //元素入队
  q.push(3);
  q.push(19);
  q.push(29);
  q.push(26);
  q.push(33);
  //元素出队
  while(!q.empty())
  {
    cout << q.front() << endl; //打印队首元素(取队首)
    q.pop(); //删除队首元素
  }
  return 0;
}


//274
#include <queue>
#include <list>
#include <iostream>
#define QUEUE_SIZE 50
int main(void)
{
  using namespace std;
  //用双向链表做queue队列的底层容器
  queue < int, list < int >  > q;
  if(q.size() < QUEUE_SIZE)
    q.push(51);
  if(q.size() < QUEUE_SIZE)
    q.push(36);
  if(q.size() < QUEUE_SIZE)
    q.push(28);
  //元素出队
  while(!q.empty())
  {
    cout << q.front() << endl; //打印51 36 28
    q.pop(); //出队
  }
  return 0;
}


//   19.3 本章小结

 

 

 

 

 

TOP

 

第19章 queue队列容器

标签:style   blog   io   color   os   sp   strong   on   div   

原文地址:http://www.cnblogs.com/xin-le/p/4111803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!