1特點
- 先進後出
- 不能進行遍歷
- 不支持隨機存儲,只能從棧頂獲取和插入元素
- 沒有迭代器
2常用API
2.1構造函數
2.2stack賦值操作函數
2.3stack數據存儲操作
2.4stack大小操作
3代碼使用
#include<iostream>
#include<stack>
using namespace std;
void tses1(){
//初始化
stack<int> s1;
stack<int> s2(s1);
//stack 操作
//增加操作
s1.push(10);
s1.push(10);
s1.push(10);
s1.push(10);
//刪除操作
s1.pop();
//打印容器數據
while(!s1.empty()){
cout<<s1.top()<<" ";
s1.pop();
}
cout<<"size: "<<s1.size()<<endl;
}
int main(){
tses1();
}