1.deque容器基本概念
2.deque构造函数
#include<deque> #include<iostream> using namespace std; void print(const deque<int>& a) { for (deque<int>::const_iterator it = a.begin(); it != a.end(); it++) { cout << *it << " "; } cout << endl; } void test() { deque<int> v1; for (int i = 0; i < 5; i++) { v1.push_back(i + 1); }; print(v1); deque<int> v2(v1.begin(), v1.end()); print(v2); deque<int> v3(10, 23); print(v3); deque<int> v5 = v1; print(v5); } int main() { test(); return 0; }
3.deque赋值操作
#include<iostream> #include<deque> using namespace std; void print(const deque<int>& v) { for (deque<int>::const_iterator it = v.begin(); it != v.end(); it++) { cout << *it << " "; } cout << endl; } void test() { deque<int> v1; for (int i = 0; i < 5; i++) { v1.push_back(i + 1); } deque<int> v2; v2.assign(v1.begin(), v1.end()); print(v2); deque<int> v3; v3.assign(10, 100); print(v3); } int main() { test(); return 0; }
4.deque大小操作
5.deque插入和删除
6.deque排序
#include<iostream> #include<deque> #include<algorithm> using namespace std; void print(const deque<int>& v) { for (deque<int>::const_iterator it = v.begin(); it != v.end(); it++) { cout << *it << " "; }; cout << endl; } void test() { deque<int> v1; v1.push_back(10); v1.push_back(20); v1.push_front(15); v1.push_front(12); print(v1); sort(v1.begin(), v1.end()); print(v1); } int main() { test(); return 0; }
7.deque数据存取
#include<iostream> #include<deque> #include<algorithm> using namespace std; void print(const deque<int>& v) { for (deque<int>::const_iterator it = v.begin(); it != v.end(); it++) { cout << *it << " "; }; cout << endl; } void test() { deque<int> v1; v1.push_back(10); v1.push_back(20); v1.push_front(15); v1.push_front(12); for (int i = 0; i < v1.size(); i++) { cout << v1[i] << " "; }; cout << endl; for (int j = 0; j < v1.size(); j++) { cout << v1.at(j) << " "; } cout << endl; cout << v1.front() << endl; cout << v1.back() << endl; } int main() { test(); return 0; }