就,STL呗

简单的数据结构

http://www.nowcoder.com/questionTerminal/c987e89ee0fa47a3a2c6383d355509b0

直接stl打就行了
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
int main(){
ios::sync_with_stdio(false);
deque<int> q;
int trash,n;
cin>>trash>>n;
while(n--){
int op;
cin>>op;
switch(op){
case 1:
int num;
cin>>num;
q.push_front(num);
break;
case 2:
q.pop_front();
break;
case 3:
int num1;
cin>>num;
q.push_back(num);
break;
case 4:
q.pop_back();
break;
case 5:
reverse(q.begin(),q.end());
break;
case 6:
cout<<q.size()<<endl;
for(auto it=q.begin();it!=q.end();it++){
if(it!=q.begin()) cout<<" ";
cout<<*it;
}
cout<<endl;
break;
case 7:
sort(q.begin(),q.end());
break;
}
}
return 0;
}</int>

全部评论

相关推荐

2 收藏 评论
分享
牛客网
牛客企业服务