-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path38.cpp
40 lines (35 loc) · 777 Bytes
/
38.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
#include<iostream>
#include<list>
#include<cstdlib> //for rand() function to generate random integers
int main()
{
//program for sorting a list
//create a list
std::list<int> l;
//inserting an integer
for(int i=0;i<10;i++)
{
l.push_back(rand());
}
//printing the contents of the list
std::cout<<"Contents of the list : ";
std::list<int>::iterator p = l.begin();
while(p!=l.end())
{
std::cout<<*p<<" ";
p++;
}
std::cout<<std::endl;
//now sorting the list
l.sort();
//printing the sorted contents
std::cout<<"Sorted Contents : ";
p = l.begin();
while(p!=l.end())
{
std::cout<<*p<<" ";
p++;
}
std::cout<<std::endl;
return 0;
}