版本比较
C++ STL之Stack栈
正文
增加 8 行删除 8 行
22 行未改动23242526272827282930313233343536363738394041424343444546474 行未改动5253545556575657585960615 行未改动676869707171727374757677787979808182834 行未改动22 行未改动## 系统类型:
```cpp#include <iostream>#include <stack> using namespace std; #include <stack>using namespace std;
int main(){ stack<int> s; s.push(1); s.push(5); s.push(7);
cout << s.size() << endl; while(!s.empty()) { cout << s.top() << " "; s.pop(); }
return 0;}```输出:4 行未改动## 自定义类型:自定义类型也是很简单的:```cpp#include <iostream>#include <stack> using namespace std; #include <stack>using namespace std;
struct node{ int val;5 行未改动 stack<node> s; s.push(node(1)); s.push(node(5)); s.push(node(7));
cout << s.size() << endl; while(!s.empty()) { node tmp = s.top(); s.pop(); cout << tmp.val << " "; }
return 0;}```输出同上。4 行未改动