构造函数:
stack<T> stk;
//stack采用模板类实现, stack对象的默认构造形式stack(const stack &stk);
//拷贝构造函数
赋值操作:
stack& operator=(const stack &stk);
//重载等号操作符
方法:
push(elem)
//入栈pop()
//出栈top()
//获取栈顶元素empty()
//判断是否为空栈size()
//获取栈的大小
示例:
#include <iostream>
#include <stack>
using namespace std;
void f1(int num){ //将一个整数的每一位按顺序输出
stack<int> s; //使用时需指定栈元素的类型
while(num){
s.push(num % 10);
num /= 10;
}
while(!s.empty()){
cout << s.top() << " ";
s.pop(); //pop方法没有返回值
}
}
int main(){
f1(12085);
}