双端队列;序列式容器(deque/vector);底层分段连续
支持从双端进行插入和删除;
综合了vector和list的优点;
插入、删除、查找的平均时间复杂度都是O(1)
部分deque的操作如下:
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <deque>
#include <thread>
using namespace std;
int main() {
deque<int> de;
deque<int> de1;
de.push_back(1);
de.push_back(10);
de.push_back(111);
de.push_back(121);
de.push_back(131);
de.push_back(141);
de.push_back(151);
std::cout << "===========iterator operator============" << std::endl;
for (auto it = de.begin(); it != de.end(); ++it) {
std::cout << *it << std::endl;
}
std::cout << "===========normal operator============" << std::endl;
for (int i = 0; i < de.size(); ++i) {
std::cout << de[i] << std::endl;
}
std::cout << "de.size()=" << de.size() << std::endl;
std::cout << "de.max_size()=" << de.max_size() << std::endl;
de1.assign(de.begin(), de.end());
for (auto d1 : de1) {
std::cout << d1 << std::endl;
}
//delete
for (auto it = de.begin(); it != de.end(); /*++it*/) {
if (131 == *it) {
it = de.erase(it);
}
else {
++it;
}
}
std::cout << "===========delete============" << std::endl;
for (auto d : de) {
std::cout << d << std::endl;
}
return 0;
}
结果: