-
Notifications
You must be signed in to change notification settings - Fork 0
/
deque_main.cpp
177 lines (149 loc) · 5.87 KB
/
deque_main.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* deque_main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ayennoui <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/01 16:43:00 by ayennoui #+# #+# */
/* Updated: 2021/03/02 18:44:29 by ayennoui ### ########.fr */
/* */
/* ************************************************************************** */
#include "deque/deque.hpp"
#include <deque>
void ft_print_deque(ft::deque<int> x)
{
ft::deque<int>::iterator it = x.begin();
while (it != x.end())
{
std::cout << *it << std::endl;
it++;
}
}
int main()
{
ft::deque<int> first; // empty deque of ints
ft::deque<int> second (4,100); // four ints with value 100
ft::deque<int> third (second.begin(),second.end()); // iterating through second
ft::deque<int> fourth (third); // a copy of third
ft::deque<int>::reverse_iterator rit;
// Iterator
// begin:
std::cout << "--------begin--------" << std::endl;
std::cout << *second.begin() << std::endl;
// end:
std::cout << "--------end--------" << std::endl;
std::cout << *second.end() << std::endl;
// rbegin:
std::cout << "--------rbegin--------" << std::endl;
std::cout << *second.rbegin() << std::endl;
// rend:
std::cout << "--------rend--------" << std::endl;
std::cout << *second.rend() << std::endl;
// size:
std::cout << "\n--------size--------" << std::endl;
std::cout << second.size() << std::endl;
// max_size:
std::cout << "\n--------max_size--------" << std::endl;
std::cout << second.max_size() << std::endl;
// resize:
std::cout << "\n--------resize--------" << std::endl;
second.resize(10, 50);
ft_print_deque(second);
std::cout << "size: " << second.size() << std::endl;
// empty:
std::cout << "\n--------empty--------" << std::endl;
std::cout << second.empty() << std::endl;
// Element access:
// operator[]:
std::cout << "\n--------operator[]--------" << std::endl;
std::cout << second[0] << std::endl;
std::cout << second[8] << std::endl;
// at:
std::cout << "\n--------at--------" << std::endl;
std::cout << second.at(0) << std::endl;
std::cout << second.at(8) << std::endl;
// front and back:
std::cout << "\n--------front and back--------" << std::endl;
std::cout << "front: " << second.front() << std::endl;
std::cout << "back: " << second.back() << std::endl;
// assign:
std::cout << "\n--------assign--------" << std::endl;
std::cout << "\n--------assign(iter)--------" << std::endl;
first.assign(second.begin(), second.end());
ft_print_deque(first);
std::cout << "\n--------assign(n, val)--------" << std::endl;
first.assign(5, -3);
ft_print_deque(first);
// push_back:
std::cout << "\n--------push_back--------" << std::endl;
first.push_back(1);
std::cout <<first.back() << std::endl;
// push_front:
std::cout << "\n--------push_front--------" << std::endl;
first.push_front(-1);
std::cout <<first.front() << std::endl;
// pop_back and pop_front:
std::cout << "\n--------pop_back and pop_front--------" << std::endl;
first.pop_back();
first.pop_front();
ft_print_deque(first);
// insert:
std::cout << "\n--------insert--------" << std::endl;
std::cout << "\n--------insert(pos, val)--------" << std::endl;
first.insert(first.begin(), 2021);
ft_print_deque(first);
std::cout << "\n--------insert(pos, n, val)--------" << std::endl;
first.insert(first.end(), 5, -6);
ft_print_deque(first);
std::cout << "\n--------insert(pos, iter, iter)--------" << std::endl;
first.insert(first.begin(),second.begin(), second.end());
ft_print_deque(first);
// erase:
std::cout << "\n--------erase--------" << std::endl;
std::cout << "\n--------erase(pos)--------" << std::endl;
first.erase(first.begin());
ft_print_deque(first);
std::cout << "\n--------erase(iter, iter)--------" << std::endl;
first.erase(first.begin(), first.end());
ft_print_deque(first);
// swap:
std::cout << "\n--------swap--------" << std::endl;
first.swap(second);
std::cout << "\n--------deque first--------" << std::endl;
ft_print_deque(first);
std::cout << "\n--------deque second--------" << std::endl;
ft_print_deque(second);
// clear:
std::cout << "\n--------clear--------" << std::endl;
first.clear();
std::cout << "\n--------deque first--------" << std::endl;
ft_print_deque(first);
ft::deque<std::string> mydeque(5, "hats");
ft::deque<std::string> otherdeque(5, "hats");
if (mydeque == otherdeque)
std::cout << "\tmydeque == otherdeque" << std::endl;
else
std::cout << "NOT\tmydeque == otherdeque" << std::endl;
if (mydeque != otherdeque)
std::cout << "\tmydeque != otherdeque" << std::endl;
else
std::cout << "NOT\tmydeque != otherdeque" << std::endl;
if (mydeque < otherdeque)
std::cout << "\tmydeque < otherdeque" << std::endl;
else
std::cout << "NOT\tmydeque < otherdeque" << std::endl;
if (mydeque > otherdeque)
std::cout << "\tmydeque > otherdeque" << std::endl;
else
std::cout << "NOT\tmydeque > otherdeque" << std::endl;
if (mydeque >= otherdeque)
std::cout << "\tmydeque >= otherdeque" << std::endl;
else
std::cout << "NOT\tmydeque >= otherdeque" << std::endl;
if (mydeque <= otherdeque)
std::cout << "\tmydeque <= otherdeque" << std::endl;
else
std::cout << "NOT\tmydeque <= otherdeque" << std::endl;
return (0);
}