#include<iostream>
#include<string>
using namespace std;
#include<stack>
#include<algorithm>
/*stack的常见接口
push(),入栈
pop(),出栈
top(),返回栈顶元素
empty(),判断栈是否为空
size(),返回栈的大小
stack<int> s;无参构造
stack<int> s2(s);拷贝构造
s3 = s2 = s;operator=重载
*/
void test() {
stack<int> s;
s.push(12);
s.push(13);
s.pop();
cout << s.top() << endl;
cout << s.size() << endl;
cout << s.empty() << endl;
stack<int> s2(s);
cout << s2.top() << endl;
stack<int> s3;
s3 = s2 = s;
cout<<s3.top() << endl;
}
int main() {
test();
return 0;
}
c++栈容器stack的常见接口
最新推荐文章于 2024-05-14 17:24:41 发布