-
Notifications
You must be signed in to change notification settings - Fork 28
/
5730059021.cpp
101 lines (88 loc) · 1.79 KB
/
5730059021.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <vector>
#include <queue>
#include <assert.h>
using namespace std;
namespace CP {
template <typename T>
class queue {
protected:
vector<T> mVect;
public:
bool empty(){
return mVect.size() == 0;
}
size_t size(){
return mVect.size();
}
T& front(){
return mVect[0];
}
T& back(){
return mVect[size()-1];
}
void push(const T& element){
mVect.push_back(element);
}
void pop(){
mVect.erase(mVect.begin());
}
};
}
void test1(){
CP::queue<int> q;
assert(q.empty() == true);
q.push(1);
q.push(2);
q.push(3);
assert(q.size() == 3);
assert(q.size() != 4);
assert(q.front() == 1);
assert(q.back() == 3);
q.pop();
assert(q.front() == 2);
assert(q.size() == 2);
assert(q.back() == 3);
q.push(27);
assert(q.back() == 27);
assert(q.size() == 3);
/* queue<int> q1;
q1 = q;
assert(q1.size() == 3);
assert(q1.front() == 2);
assert(q1.back() == 27);*/
}
void test2(){
CP::queue<vector<int>> q;
vector<int> v1;
vector<int> v2;
for(int i = 1 ; i <= 10 ; i++){
v1.push_back(i*10);
}
q.push(v1);
q.push(v2);
assert(q.size() == 2);
assert(q.front()[0] == 10);
assert(q.back().empty() == true);
}
void test3(){
CP::queue<string> q;
size_t n = 50000;
for(size_t i = 0 ; i < n ; i++){
string a = "a";
q.push(a);
}
assert(q.size() == n);
assert(q.front() == "a");
assert(q.back() == "a");
for (size_t i = q.size(); i > 1 ; i--){
q.pop();
}
assert(q.size() == 1);
assert(q.front() == "a");
}
int main() {
test1(); cout << "test1 OK " << endl;
test2(); cout << "test2 OK " << endl;
test3(); cout << "test3 OK " << endl;
}