forked from nguliu/mySTL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeque_test.cpp
68 lines (54 loc) · 1.63 KB
/
deque_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "pch.h"
#include <iostream>
#include "deque.h"
using namespace mySTL;
using namespace std;
int main() {
deque<int, alloc, 8> que(20, 9); //构造一个拥有20个int型元素初值为9、缓冲区为8个元素的deque
//为每个元素设定新值
for (int i = 0; i < que.size(); ++i) {
que[i] = i;
}
cout << "1: que.size() = " << que.size() << endl;
for (int i : que)
cout << i << " ";
cout << endl << endl;
//在尾端压入三个元素,此时三个缓冲区刚好填满(左闭右开原则会留一个空的位置)
for (int i = 0; i < 3; ++i) {
que.push_back(20 + i);
}
cout << "2: que.size() = " << que.size() << endl;
for (int i : que) {
cout << i << " ";
}
cout << endl << endl;
//在尾端增加一个元素 23,此时需要生成新的缓冲区
que.push_back(23);
cout << "3: que.size() = " << que.size() << endl;
for (int i : que) {
cout << i << " ";
}
cout << endl << endl;
//在前端压入三个元素
for (int i = 0; i < 3; ++i) {
que.push_front(100 + i);
}
cout << "4: que.size() = " << que.size() << endl;
for (int i : que) {
cout << i << " ";
}
cout << endl << endl;
que.erase(que.begin() + 4, que.begin() + 10);
cout << "5: que.size() = " << que.size() << endl;
for (deque<int, alloc, 8>::iterator it = que.begin(); it < que.end(); ++it) {
cout << *it << " ";
}
cout << endl << endl;
que.insert(que.begin() + 10, 8888);
cout << "6: que.size() = " << que.size() << endl;
for (deque<int, alloc, 8>::iterator it = que.begin(); it < que.end(); ++it) {
cout << *it << " ";
}
cout << endl << endl;
return 0;
}