1 #include <iostream> 2 #include <stack> 3 #include <algorithm> 4 #include <list> 5 #include <vector> 6 using namespace std; 7 8 9 void main() 10 { 11 //声明栈,默认是deque(因为删除插入效率比较高) 12 stack<int> mystack; 13 //声明链式栈 14 stack<int, list<int>> myliststack; 15 //声明数组栈 16 stack<int, vector<int>> myliststack2; 17 mystack.push(1); 18 mystack.push(2); 19 mystack.push(3); 20 mystack.push(4); 21 22 while (!mystack.empty()) 23 { 24 cout << mystack.top() << endl; 25 mystack.pop(); 26 } 27 28 cin.get(); 29 }