1 #include <iostream> 2 #include <deque> 3 4 using namespace std; 5 6 int main() 7 { 8 // 插入 9 deque<int> de; 10 for(int i=0;i<5;++i) 11 { 12 de.push_back(i); 13 } 14 15 for(int i=1;i<=5;++i) 16 { 17 de.push_front(i*10); 18 } 19 20 for(deque<int>::iterator it=de.begin();it!=de.end();++it) 21 { 22 cout<<*it<<" "; 23 } 24 cout<<endl; 25 26 // 删除 27 de.pop_back(); 28 de.pop_front(); 29 for(deque<int>::iterator it=de.begin();it!=de.end();++it) 30 { 31 cout<<*it<<" "; 32 } 33 cout<<endl; 34 35 // 求当前迭代器位置 36 for(deque<int>::iterator it=de.begin();it!=de.end();++it) 37 { 38 cout<<distance(de.begin(),it)<<" "; 39 } 40 cout<<endl; 41 42 }
#include <iostream>#include <deque>
using namespace std;
int main(){ // 插入 deque<int> de; for(int i=0;i<5;++i) { de.push_back(i); }
for(int i=1;i<=5;++i) { de.push_front(i*10); }
for(deque<int>::iterator it=de.begin();it!=de.end();++it) { cout<<*it<<" "; } cout<<endl;
// 删除 de.pop_back(); de.pop_front(); for(deque<int>::iterator it=de.begin();it!=de.end();++it) { cout<<*it<<" "; } cout<<endl;
// 求当前迭代器位置 for(deque<int>::iterator it=de.begin();it!=de.end();++it) { cout<<distance(de.begin(),it)<<" "; } cout<<endl;
}