c++ set用法详解
- stack
- stack常用操作
- 例题
栈是基本的数据结构之一,特点是先进后出,就如开进死胡同的车队,先进去的只能最后出来.
在c++ 中,stack的头文件是#include
stackq; //以int型为例 int x; q.push(x); //将x压入栈顶 q.top(); //返回栈顶的元素 q.pop(); //删除栈顶的元素 q.size(); //返回栈中元素的个数 q.empty(); //检查栈是否为空,若为空返回true,否则返回false
#include#include using namespace std; int main() { stack q; q.push(1); q.push(2); q.push(3); q.push(4); q.push(5); cout<<"q.size "< 例题 题目: 51Nod - 3199 操作栈
代码
#include#include using namespace std; int main() { stack q; int n,op,x; cin>>n; while(n--) { cin>>op; if(op==1) { cin>>x; q.push(x); } else if(op==2) { if(q.empty()) cout<<"empty"< cout<
c++ set用法详解



