-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisttest.cpp
48 lines (32 loc) · 817 Bytes
/
listtest.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
#include <iostream>
#include <list>
using namespace std;
int main()
{
list<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
for (string car : cars)
{
cout << car << "\n";
}
// Get the first element
cout << cars.front();
// Get the last element
cout << cars.back();
// Change the value of the first element
cars.front() = "Opel";
// Change the value of the last element
cars.back() = "Toyota";
cout << cars.front();
cout << cars.back();
// Add an element at the beginning
cars.push_front("Tesla");
// Add an element at the end
cars.push_back("VW");
// Remove the first element
cars.pop_front();
// Remove the last element
cars.pop_back();
cout << cars.size();
cout << cars.empty();
return 0;
}