STL十大容器 之 双端队列 deque

简介:

deque 双端(向)队列

 #include <deque>

双端队列具有以下特点:
1、允许在两端进行插入和删除
2、在时间复杂度上会比向量更加复杂
3、本质上和vector很相似 , 但是内存机制比起vector更加复杂:
比vector多了 push_front pop_front方法 少了capacity 和 reserve

程序示例:

#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;

int main(){
	deque<int> deq;
	deq.push_front(1);
	deq.push_back(2);
	deq.push_front(3);
	deq.push_back(4);
	sort(deq.begin(),deq.end());
	deque<int>::iterator it = deq.begin();
	for(;it != deq.end(); ++it){
		cout << *it << " ";	
	}
	cout << endl;
	deq.pop_front();
	for(it=deq.begin();it != deq.end();++it){
		cout << *it << " ";	
	}
	cout << endl;
	return 0;	
}
发布了53 篇原创文章 · 获赞 18 · 访问量 7239

猜你喜欢

转载自blog.csdn.net/Nire_Yeyu/article/details/100993387
今日推荐