stack容器
1-特性总结 (1)先进后出 (2)栈不提供迭代器,因此不能遍历,不支持随机存取,只能通过top从栈顶获取和删除元素 (3)只能通过栈顶一个一个给里面加元素,通过栈顶一个一个删除元素
实例
#include<iostream>
#include<stack>
using namespace std
;
void test01() {
stack
<int>s1
;
stack
<int>s2(s1
);
s1
.push(10);
s1
.push(20);
s1
.push(30);
s1
.push(100);
cout
<< "栈顶元素:" << s1
.top() << endl
;
s1
.pop();
while (!s1
.empty()) {
cout
<< s1
.top() << " ";
s1
.pop();
}
cout
<< s1
.size() << endl
;
}
int main() {
test01();
return 0;
}
转载请注明原文地址: https://mac.8miu.com/read-500639.html