-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.cpp
More file actions
60 lines (47 loc) · 991 Bytes
/
Copy pathlist.cpp
File metadata and controls
60 lines (47 loc) · 991 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
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <list> // built using Doubly LinkedList
using namespace std;
int main()
{
list<int> l;
l.push_back(1);
l.push_front(2);
for (int i : l)
{
cout << i << " -> ";
}
cout << endl;
// l.pop_back();
// l.pop_front();
// for (int i : l)
// {
// cout << i << " -> ";
// }
// cout << endl;
cout << "Front -> " << l.front() << endl;
cout << "Back -> " << l.back() << endl;
cout << "Empty or not -> " << l.empty() << endl;
cout << "before erase -> " << l.size() << endl;
l.erase(l.begin());
cout << "after erase -> " << l.size() << endl;
for (int i : l)
{
cout << i << " -> ";
}
cout << endl;
// copying one list to another
list<int> n(l);
for (int i : n)
{
cout << i << " -> ";
}
cout << endl;
// creating a list with values
list<int> n2(5, 100); // list will be created with 5 elements all being 100
for (int i : n2)
{
cout << i << " -> ";
}
cout << endl;
return 0;
}