重要的数据结构。
操作:
#include <stack>
#include <iostream>
using namespace std;
int main() {
stack<int> intStack;
// 压 4个元素入栈
intStack.push(16);
intStack.push(8);
intStack.push(20);
intStack.push(3);
// 取栈顶元素,并弹栈
cout << "top of intStack:" << intStack.top() << endl;
intStack.pop();
cout << "top of intStack:" << intStack.top() << endl;
while(!intStack.empty()) {
cout << intStack.top() << " ";
intStack.pop();
}
cout << endl;
return 0;
}
原文:http://blog.csdn.net/haifengzhilian/article/details/23676775