码迷,mamicode.com
首页 > 其他好文 > 详细

双端队列

时间:2016-12-04 06:53:56      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:push   ret   code   namespace   str   插入   deque   pop   ever   

//插入元素//
#include<iostream> #include<deque> using namespace std; int main() { deque<int> d; d.push_back(1);//尾部插入 d.push_back(2); d.push_back(3); d.push_front(10);//d.insert(d.begin()+1, 10);头部插入 d.push_front(20);//d.insert(d.begin()+2, 20); cout<<d[0]<<" "<<d[1]<<" "<<d[2]<<endl; return 0; }
//遍历//
#include<iostream> #include<deque> using namespace std; int main() { deque<int> d; d.push_back(1); d.push_back(2); d.push_back(3); for(int i = 0; i < d.size(); i ++) cout<<d[i]<<" "; cout<<endl; deque<int>::iterator it; for(it = d.begin(); it != d.end(); it ++) cout<<*it<<" "; cout<<endl; deque<int>::reverse_iterator rit; for(rit = d.rbegin(); rit != d.rend(); rit ++) cout<<*rit<<" ";//反向遍历 cout<<endl; return 0; }
//删除//
#include<iostream> #include<deque> using namespace std; int main() { deque<int> d; for(int i = 1; i < 6; i ++) d.push_back(i); d.pop_front(); d.pop_front(); deque<int>::iterator it; for(it = d.begin(); it != d.end(); it ++) cout<<*it<<" "; cout<<endl; d.pop_back(); for(it = d.begin(); it != d.end(); it ++) cout<<*it<<" "; cout<<endl; d.erase(d.begin()+1); for(it = d.begin(); it != d.end(); it ++) cout<<*it<<" "; cout<<endl; d.clear(); cout<<d.size()<<endl; return 0; }

 

双端队列

标签:push   ret   code   namespace   str   插入   deque   pop   ever   

原文地址:http://www.cnblogs.com/xlqtlhx/p/6130029.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!