题解 | #简单的数据结构#
简单的数据结构
https://ac.nowcoder.com/acm/problem/14661
学习一种新的STL
双向队列 头文件是#include
#include<set>
#include<deque>
#include<algorithm>
using namespace std;
int n,a[100010],m;
deque<int> q;
int main(){
cin >>n>>m;
int x,y;
while(m--){
cin >>x;
if(x ==1) {
cin >>y;
q.push_front(y);
}
else if(x == 2){
q.pop_front();
}
else if(x==3){
cin >> y;
q.push_back(y);
}
else if(x ==4){
q.pop_back();
}
else if(x ==5){
reverse(q.begin(),q.end());
}
else if(x==6){
int j = q.size();
cout<<j<<endl;
for(int i =0;i<j;i++){
cout<<q[i]<<" ";
}
cout<<endl;
}
else {
sort(q.begin(),q.end());
}
}
return 0;
}
基础