STL(十八)stack堆栈容器

来源:互联网 发布:网络建设与管理试题 编辑:程序博客网 时间:2024/05/21 06:14

一、stack技术原理

       

二、stack应用基础

#include <stack>

1、创建stack对象

       stack()

       stack(const  stack &)

2、元素入栈

       push(const  value_type  &x)

3、元素出栈

       void  pop()

4、取栈顶元素

       value_type&   top()

5、堆栈非空判断

       bool    empty()

6、堆栈的大小

       size_type   size()

#include <stack>#include <list>#include <iostream>#define  STACK_SIZE    100int 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;} 

原创粉丝点击