#include <bits/stdc++.h>
using namespace std;
struct Node {
string x, y, z;
Node (string x, string y, string z) : x(x), y(y), z(z) {};
};
stack<Node> st; //结构体栈
stack<string> s;
int main () {
s.push ("ULTRAMAN");
s.push ("DOGE");
cout << "empty?: " << s.empty() << endl; //不是空的,输出0
cout << s.size() << endl;
cout << s.top() << endl;
s.pop();
cout << s.top() << endl;
s.pop();
cout << "empty?: " << s.empty() << endl; //输出1
s.push ("CARD");
s.push ("DOGE");
while (!s.empty()) s.pop();
cout << "empty?: " << s.empty();
// ---------普通栈操作↑----------
// ---------结构体栈↓----------
st.push (Node ("ORB", "GEED", "ZERO"));
st.push (Node ("GAYA", "X", "DANA"));
cout << st.size() << endl;
cout << st.top().x << " " << st.top().y << " " << st.top().z << endl;
st.pop();
cout << st.top().x << " " << st.top().y << " " << st.top().z;
return 0;
}
正版STL栈的基本操作
最新推荐文章于 2024-10-09 10:07:13 发布