-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathForward_List.cpp
More file actions
90 lines (90 loc) · 2.57 KB
/
Forward_List.cpp
File metadata and controls
90 lines (90 loc) · 2.57 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <forward_list>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
forward_list<int> fl, fl1 = {5, 6, 3, 2, 7};
forward_list<int>::iterator it;
int choice, item;
while (1)
{
cout<<"\n---------------------"<<endl;
cout<<"Forward_List Implementation in Stl"<<endl;
cout<<"\n---------------------"<<endl;
cout<<"1.Insert Element at the Front"<<endl;
cout<<"2.Delete Element at the Front"<<endl;
cout<<"3.Front Element of Forward List"<<endl;
cout<<"4.Resize Forward List"<<endl;
cout<<"5.Remove Elements with Specific Values"<<endl;
cout<<"6.Remove Duplicate Values"<<endl;
cout<<"7.Reverse the order of elements"<<endl;
cout<<"8.Sort Forward List"<<endl;
cout<<"9.Merge Sorted Lists"<<endl;
cout<<"10.Display Forward List"<<endl;
cout<<"11.Exit"<<endl;
cout<<"Enter your Choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter value to be inserted at the front: ";
cin>>item;
fl.push_front(item);
break;
case 2:
item = fl.front();
fl.pop_front();
cout<<"Element "<<item<<" deleted"<<endl;
break;
case 3:
cout<<"Front Element of the Forward List: ";
cout<<fl.front()<<endl;
break;
case 4:
cout<<"Enter new size of Forward List: ";
cin>>item;
if (item <= fl.max_size())
fl.resize(item);
else
fl.resize(item, 0);
break;
case 5:
cout<<"Enter element to be deleted: ";
cin>>item;
fl.remove(item);
break;
case 6:
fl.unique();
cout<<"Duplicate Items Deleted"<<endl;
break;
case 7:
fl.reverse();
cout<<"Forward List reversed"<<endl;
break;
case 8:
fl.sort();
cout<<"Forward List Sorted"<<endl;
break;
case 9:
fl1.sort();
fl.sort();
fl.merge(fl1);
cout<<"Forward List Merged after sorting"<<endl;
break;
case 10:
cout<<"Elements of Forward List: ";
for (it = fl.begin(); it != fl.end(); it++)
cout<<*it<<" ";
cout<<endl;
break;
case 11:
exit(1);
break;
default:
cout<<"Wrong Choice"<<endl;
}
}
return 0;
}