首页 > 其他 > 详细

第18章 stack堆栈容器

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

 

 

 

 

 

/*

  第18章 stack堆栈容器
   18.1 stack技术原理
   18.2 stack应用基础
   18.3 本章小结
*/


//  第18章 stack堆栈容器
//   18.1 stack技术原理 ------------

//   18.2 stack应用基础 ---------------------------------------------------------------------------------


//268
#include <stack>
#include <iostream>
int main(void)
{
  using namespace std;
  //创建堆栈对象
  stack < int > s;
  //元素入栈
  s.push(3);
  s.push(19);
  s.push(23);
  s.push(36);
  s.push(50);
  //元素依次出栈
  while(!s.empty())
  {
    cout << s.top() << endl; //打印栈顶元素
    s.pop(); //出栈
  }
  return 0;
}


//268-269
#include <stack>
#include <list>
#include <iostream>
#define STACK_SIZE 100  //堆栈最大容量
int main(void)
{
  using namespace std;
  stack < int, list < int >  > s; //用双向链表做堆栈的底层结构
  if(s.size() < STACK_SIZE)
    s.push(68);
  if(s.size() < STACK_SIZE)
    s.push(1);
  if(s.size() < STACK_SIZE)
    s.push(17);
  //
  while(!s.empty())
  {
    cout << s.top() << endl;
    s.pop();
  }
  return 0;
}


//   18.3 本章小结 --------------------------------------------------------------------------------------

 

 

 

 

 

 

 TOP

 

第18章 stack堆栈容器

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

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