1 /*关于C++ STL中deque的学习*/ 2 #include<cstdio> 3 #include<iostream> 4 #include<deque> 5 6 using namespace std; 7 void print(deque<int> d); 8 void rprint(deque<int> d); 9 int main() 10 { 11 deque<int> dq; 12 dq.push_back(1); 13 dq.push_back(2); 14 dq.push_back(3); 15 dq.push_back(4); 16 cout<<dq.size()<<endl; 17 cout<<dq[0]<<" "<<dq[1]<<" "<<dq[2]<<" "<<dq[3]<<endl; 18 19 dq.push_front(0); 20 cout<<dq.size()<<endl; 21 cout<<dq[0]<<" "<<dq[1]<<" "<<dq[2]<<" "<<dq[3]<<" "<<dq[4]<<endl; 22 23 dq.insert(dq.begin()+2,8); 24 cout<<dq.size()<<endl; 25 cout<<dq[0]<<" "<<dq[1]<<" "<<dq[2]<<" "<<dq[3]<<" "<<dq[4]<<" "<<dq[5]<<endl; 26 27 cout<<"##"<<endl; 28 print(dq); 29 dq.pop_front(); 30 print(dq); 31 32 print(dq); 33 dq.pop_back(); 34 print(dq); 35 36 print(dq); 37 dq.clear(); 38 cout<<"##"<<endl; 39 print(dq); 40 cout<<"##"<<endl; 41 return 0; 42 } 43 44 void print(deque<int> d){ 45 for(int i=0;i<d.size();i++){ 46 printf("%d ",d[i]); 47 } 48 puts(""); 49 } 50 51 void rprint(deque<int> d){ 52 for(int i=d.size()-1;i>=0;i--){ 53 printf("%d ",d[i]); 54 } 55 puts(""); 56 }
原文地址:https://www.cnblogs.com/wenzhixin/p/9129773.html
时间: 2024-10-05 02:00:10