forked from Saad2714/Cpp-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.cpp
54 lines (45 loc) · 1.12 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
52
53
54
#include <iostream>
#include <list>
using namespace std;
int main()
{
list <int> LI;
list <int>::iterator it;
//inserts elements at end of list
LI.push_back(4);
LI.push_back(5);
//inserts elements at beginning of list
LI.push_front(3);
LI.push_front(5);
//returns reference to first element of list
it = LI.begin();
//inserts 1 before first element of list
LI.insert(it,1);
cout<<"All elements of List LI are: " <<endl;
for(it = LI.begin();it!=LI.end();it++)
{
cout<<*it<<" ";
}
cout<<endl;
//reverse elements of list
LI.reverse();
cout<<"All elements of List LI are after reversing: " <<endl;
for(it = LI.begin();it!=LI.end();it++)
{
cout<<*it<<" ";
}
cout<<endl;
//removes all occurences of 5 from list
LI.remove(5);
cout<<"Elements after removing all occurence of 5 from List"<<endl;
for(it = LI.begin();it!=LI.end();it++)
{
cout<<*it<<" ";
}
cout<<endl;
//removes last element from list
LI.pop_back();
//removes first element from list
LI.pop_front();
return 0;
}