#include<stack>
#include<iostream>
using namespace std;
void test01() {
//初始化
stack<int> s1; //默认构造
stack<int> s2(s1); //拷贝构造
//存取操作
s1.push(10);
s1.push(20);
s1.push(30);
s1.push(40);
s1.push(100);
cout << "此时的栈顶元素top:" << s1.top() << endl;
s1.pop();
cout << "此时的栈顶元素top:" << s1.top() << endl;
cout << "s2.size: " << s2.size() << endl;
//赋值
s2 = s1;
cout << "s2.size: " << s2.size() << endl;
//打印栈容器数据
while (!s2.empty()) {
cout << s2.top() << " ";
s2.pop();
}
}
int main() {
test01();
cout << endl << endl;
return 0;
}
黑马程序员C++提高5——stack容器【栈】
猜你喜欢
转载自blog.csdn.net/qq_43685399/article/details/108610696
今日推荐
周排行