C++ STL stack栈

来源:互联网 发布:抢客软件 编辑:程序博客网 时间:2024/05/17 01:33

    stl真是个好东西,方便了很多。直接上代码。

#include <iostream>#include <stack>#include <vector>#include <list>using namespace std;/*stack:栈(后进先出)stack:自适应容器、栈适配器s.empty():检查(堆)栈是否为空s.size():检查(堆)栈中有多少个数据s.pop():从(堆)栈中取出一个数据,该数据于(堆)栈中自动删除s.top():查看栈顶数据,不做删除s.push(item)将一个数据压入(堆)栈中*/void main() {stack<int, deque<int>>a;stack<int, vector<int>>b;stack<int, list<int>>c;stack<int>d;//默认使用stack<int, deque<int>>d.push(25);d.push(10);d.push(1);d.push(5);cout << "现在栈内数据:" << d.size() << "个数据\n";//while (d.size() != 0)   //可以//while (!d.empty())   //也可以 {int x = d.top();//查看数据并返回d.pop();//删除不返回cout << x << endl;}cout << "现在栈内数据:" << d.size() << "个数据\n";system("pause");}


0 0
原创粉丝点击