-
Notifications
You must be signed in to change notification settings - Fork 7
/
list.cpp
51 lines (42 loc) · 1.07 KB
/
list.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
#include <iostream>
#include <list>
using namespace std;
int main()
{
// declaration
list<int> ls;
// assigning values
ls.push_back(1);
ls.push_back(3);
ls.push_back(2);
ls.push_back(4);
ls.push_front(0);
// printing a list
for (auto i : ls)
cout << i << " ";
cout << endl;
// declaration with given dingle value
list<int> l(5, 10);
cout << "this list will print like this ";
for (auto i : l)
cout << i << " ";
cout << endl;
// deleting the first element
ls.erase(ls.begin());
cout << "After deleting first element : ";
for (auto i : ls)
cout << i << " ";
cout << endl;
// deleting the first or the last element
ls.pop_back();
ls.pop_front();
cout << "After deleting front and back element : ";
for (auto i : ls)
cout << i << " ";
cout << endl;
// size of the list
cout << "The size of the list is " << ls.size() << endl;
// iterators
cout << "front and back iterators are " << *ls.begin() << " ls.end()" << endl;
return 0;
}