deque容器
double - ended - queue (双端队列)
- 适用场景
频繁在队头和队尾插入删除的队列 - 常用方法
见老哥的文章:click here - 一些性质
deque存放的元素的物理位置不保证连续,验证
#include<iostream>
#include <stdlib.h>
#include<deque>
using namespace std;
int main(){
deque<int>d;
for(int i = 0; i < 200; i++)
d.push_back(rand());
for(int i = 0; i < 200; i++)
cout << &d[i] << endl;
return 0;
}
注意看红线处跳跃的地址
底层实现(动态分配分段连续的存储空间)
原图出自:click here
通过一个map指针数组保存各空间地址,这样去实现队头的插入删除,可以节省存储空间。