-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path44_sortlist.cpp
52 lines (47 loc) · 999 Bytes
/
44_sortlist.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
#include<iostream>
#include<list>
using namespace std;
void display(list<int> &lst)
{
list<int>::iterator itr;
cout << "List : ";
for (itr = lst.begin(); itr !=lst.end(); itr++)
{
cout << *itr << " ";
}
cout<<endl;
}
int main ()
{
list<int> list1; // List of size 0
list1.push_back(4);
list1.push_back(5);
list1.push_back(3);
list1.push_back(5);
list1.push_back(9);
list1.push_back(2);
cout<<"First ";
display(list1);
list1.reverse();
cout<<"Reverse ";
display(list1);
cout<<"After sorting ";
list1.sort();
display(list1);
// list1.unique(); : Remove duplicates
list<int> list2(5); // Empty list of size 5
list<int> :: iterator itr=list2.begin();
*itr++=4;
*itr++=8;
*itr++=4;
*itr++=8;
*itr=4;
cout<<"Second ";
display(list2);
list2.sort();
display(list2);
cout<<"After merge ";
list1.merge(list2);
display(list1);
return 0;
}