栈<stack>

 1 //栈的基本函数
 2 //头文件包  #include<stack>
 3 #include<stack>
 4 #include<iostream>
 5 using namespace std;
 6 
 7 stack <int>  s;
 8 int main(){
 9   for(int i=1;i<=5;i++)
10     s.push(i);//入栈 
11   int x=s.top();//取最上面一位,栈顶
12   //出栈 s.pop();s.size()计算栈长
13   while(s.empty()!=0){
14     int x=s.top();
15     s.pop();
16     cout<<x;
17   } 
18 }

猜你喜欢

转载自www.cnblogs.com/1129-tangqiyuan/p/9503583.html