-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdequetest.cpp
More file actions
49 lines (36 loc) · 885 Bytes
/
Copy pathdequetest.cpp
File metadata and controls
49 lines (36 loc) · 885 Bytes
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
#include <iostream>
#include <deque>
using namespace std;
// double ended queue elements can add and remove on both front and back
int main()
{
deque<string> cars;
// Add elements to the queue
cars.push_back("Volvo");
cars.push_back("BMW");
cars.push_back("Ford");
cars.push_back("Mazda");
cars.push_back("Tesla");
// Print deque elements
for (string car : cars)
{
cout << car << "\n";
}
// Get the first element
cout << cars.front();
// Get the last element
cout << cars.back();
// Get the element by position
cout << cars.at(1);
cout << cars.at(2);
// update element
cars[0] = "Opel";
cars.at(1) = "Ford";
// Remove the first element
cars.pop_front();
// Remove the last element
cars.pop_back();
cout << cars.size();
cout << cars.empty();
return 0;
}