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

  • 相关阅读:
    Create procedure
    json
    XSLT
    使用 ActiveMQ 示例
    使用Apache FtpServer搭建FTP服务器
    Publisher/Subscriber(发布/订阅者)消息模式开发流程
    使用 ActiveMQ 示例
    内嵌jetty
    基于Atom协议的数据接入规范
    C++创建jni 并且利用rundll32.exe调试jni程序
  • 原文地址:https://www.cnblogs.com/xin-le/p/4111786.html
Copyright © 2011-2022 走看看