小吴不吃葱 • 3个月前
using namespace std; stack s;
int main() {
int n, x;
cout << "入栈n个:";
cin >> n;
while (n--) {
cin >> x;
s.push(x);
}
if (s.empty()) {
cout << "栈空" << endl;
} else {
cout << "栈不空" << endl;
}
cout << "大小:" << s.size() << endl;
cout << "栈顶:" << s.top() << endl;
cout << "出栈n个:";
cin >> n;
while (n--) {
cout << "出栈元素:" << s.top() << endl;
s.pop();
}
if (s.size() == 0) {
cout << "栈空" << endl;
} else {
cout << "栈不空" << endl;
}
return 0;
}
评论:
请先登录,才能进行评论