deque双端队列(常用方法总结)

时间:2021-06-30 15:39:44
 /*关于C++ STL中deque的学习*/
#include<cstdio>
#include<iostream>
#include<deque> using namespace std;
void print(deque<int> d);
void rprint(deque<int> d);
int main()
{
deque<int> dq;
dq.push_back();
dq.push_back();
dq.push_back();
dq.push_back();
cout<<dq.size()<<endl;
cout<<dq[]<<" "<<dq[]<<" "<<dq[]<<" "<<dq[]<<endl; dq.push_front();
cout<<dq.size()<<endl;
cout<<dq[]<<" "<<dq[]<<" "<<dq[]<<" "<<dq[]<<" "<<dq[]<<endl; dq.insert(dq.begin()+,);
cout<<dq.size()<<endl;
cout<<dq[]<<" "<<dq[]<<" "<<dq[]<<" "<<dq[]<<" "<<dq[]<<" "<<dq[]<<endl; cout<<"##"<<endl;
print(dq);
dq.pop_front();
print(dq); print(dq);
dq.pop_back();
print(dq); print(dq);
dq.clear();
cout<<"##"<<endl;
print(dq);
cout<<"##"<<endl;
return ;
} void print(deque<int> d){
for(int i=;i<d.size();i++){
printf("%d ",d[i]);
}
puts("");
} void rprint(deque<int> d){
for(int i=d.size()-;i>=;i--){
printf("%d ",d[i]);
}
puts("");
}