-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforward_list.cpp
More file actions
40 lines (28 loc) · 1.04 KB
/
forward_list.cpp
File metadata and controls
40 lines (28 loc) · 1.04 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
#include<iostream>
#include<forward_list>
using namespace std;
// Same As Single Linked List Of C Language
int main()
{
forward_list<int> list1 = {5,4,6,2}; // Definition
forward_list<int> list2 = {7,1,8,9};
list1.sort();
list2.sort(); // Sorts The List
list1.merge(list2); // Merges list2 at end of list1
list1.reverse(); // Reverse The List
list1.insert_after(list1.begin(),5); //Adds 5 after 1 element in the list
list1.splice_after(list1.begin(),list2); /*Splices List2 and add data of
list2 in list1 after list.begin() */
cout<<"Size of List 2 : "<<distance(list2.begin(),list2.end())<<endl;
// Gives The Distance Between The Two Parameters Given
list1.resize(2);
//Resizes The List Remove The Last Elements if size given is less than original
// If Size given is Greater Than Original Then Puts 0 in the Ending Places
list1.unique(); // Removes All Adjacents Duplicates
list1.remove(2); // Removes All Appearance of Given Parameters
for(auto element : list1)
{
cout<<element<<endl;
}
return 0;
}