原c++栈的方法的基本用法:
1.push(): 向栈内压入一个成员;
2.pop(): 从栈顶弹出一个成员;
3.empty(): 如果栈为空返回true,否则返回false;
4.top(): 返回栈顶,但不删除成员;
5.size(): 返回栈内元素的大小;
代码示例
#include<iostream>
#include<stack>
using namespace std;
int main()
{
stack <int>stk;
//入栈
for(int i=0;i<50;i++){
stk.push(i);
}
cout<<"栈的大小:"<<stk.size()<<endl;
while(!stk.empty())
{
cout<<stk.top()<<endl;
stk.pop();
}
cout<<"栈的大小:"<<stk.size()<<endl;
return 0;
}