首页 > 其他 > 详细

第19章 queue队列容器

时间:2014-11-21 01:12:46      阅读:276      评论:0      收藏:0      [点我收藏+]

 

 

/*

  第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队列容器

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!