-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathlist stl.cpp
101 lines (82 loc) · 1.91 KB
/
list stl.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include<list>
using namespace std;
int main() {
cout<<"Hello World!\n";
//initialising and creating
list<int> l;
list<int> l1{1,2,3,4,5,6,7,8,9,0};
//different data type
list<string> l2{"apple","mango","banana","guava","raspberry","kiwi","orange","watermelon"};
//adding the element in the list
l2.push_back("pineapple");
//iterate over the list
for(auto x:l2)
cout<<x<<"-->";
cout<<endl;
//sorting the list
l2.sort();
for(auto x:l2)
cout<<x<<"-->";
cout<<endl;
//reversing the list
l2.reverse();
for(auto x:l2)
cout<<x<<"-->";
cout<<endl;
//removing the first element
l2.pop_front();
for(auto x:l2)
cout<<x<<"-->";
cout<<endl;
//printing the front element
cout<<l2.front()<<"!!"<<endl;
//adding to the front element
l2.push_front("grapes");
for(auto x:l2)
cout<<x<<"-->";
cout<<endl;
cout<<l2.back()<<endl;
l2.pop_back();
for(auto x:l2)
cout<<x<<"-->";
cout<<endl;
//iterete the loop using itetrator
for(auto it=l2.begin();it!=l2.end();it++)
{
cout<<(*it)<<" <*-*> ";
} cout<<endl;
//adding more element on the list
l2.push_back("starfruit");
l2.push_back("lemon");
l2.push_back("starfruit");
l2.push_back("starfruit");
l2.push_back("starfruit");
for(auto x:l2)
cout<<x<<" <=> ";
cout<<endl;
//removing A fruit
string f;
cin>>f;
l2.remove(f);
for(auto x:l2)
cout<<x<<" <=> ";
cout<<endl;
//erasing some element
auto it=l2.begin();
it++;
it++;
it++;
l2.erase(it);
for(auto x:l2)
cout<<x<<" <=> ";
cout<<endl;
//insert at any pos
it=l2.begin();
it++;
l2.insert(it,"chiku");
for(auto x:l2)
cout<<x<<" <=> ";
cout<<endl;
return 0;
}