zoukankan      html  css  js  c++  java
  • 第18章 stack堆栈容器

     

    /*
    
      第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

  • 相关阅读:
    Python3 函数return
    Python3 函数参数
    计算机组成原理基础
    解决 Python2 和 Python3 的共存问题
    管理本地用户和组
    Linux 常用命令(二)
    Linux 控制台
    Linux 常用命令(一)
    Linux中的目录功能(Red Hat 7)
    自定义属性使用
  • 原文地址:https://www.cnblogs.com/xin-le/p/4111786.html
Copyright © 2011-2022 走看看