主要操作:
常用函数列举:
|函数名|功能|
|-|-|
|size()|返回栈的元素个数|
|top()|返回栈顶元素|
|pop()|弹出栈顶元素|
|push()|向栈中添加元素|
|empty()|在栈为空时返回true|
程序实例:
/* STL 使用 栈 的示例 */
#include<iostream>
#include<stack>
using namespace std;
typedef int ElementType; /* 自定义栈的元素 */
int main()
{
stack <ElementType> sta;
if(sta.empty()) cout<<"栈为空"<<endl;
sta.push(5);
if(!sta.empty()) cout<<"栈不为空"<<endl;
cout<<sta.top()<<endl;
cout<<sta.size()<<endl;
sta.pop();
if(sta.empty()) cout<<"栈为空"<<endl;
system("pause");
return 0;
}