-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSTL Linked List Operations.cpp
More file actions
71 lines (52 loc) · 1.28 KB
/
Copy pathSTL Linked List Operations.cpp
File metadata and controls
71 lines (52 loc) · 1.28 KB
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
#include<iostream>
#include<list>
using namespace std;
int main()
{
list<int> l;
//Creating a int list
list<int> l1{1,2,3,4,5,6};
//Creating in a sring list
list<string> l2{"apple","guava","mango","banana"};
//Push back function
l2.push_back("pineapple");
//sort
l2.sort();
//reverse
l2.reverse();
//Printing the first element
cout<<l2.front()<<endl;
//Removing the first element
l2.pop_front();
//Adding a element in the front
l2.push_front("kiwi");
//Removing the last element of the list
l2.pop_back();
//Printing the last element of the list
cout<<l2.back()<<endl;
//Iterate over the list using Iterators
for(auto it = l2.begin(); it!= l2.end() ; it++)
{
cout<<(*it)<<" -> ";
}
cout<<endl;
//remove a fruit
string f;
cin>>f;
l2.remove(f);
//Erase one or more elements
auto it = l2.begin();
it++;
it++;
//Would remove the element from the second position in the list
l2.erase(it);
//Inserting the element in the list
it = l2.begin();
it++;
l2.insert(it,"Fruit Juice");
//Printing all nodes in the Linked List
for (string s:l2)
{
cout<<s<<"-->";
}
}