forked from thakursaurabh1998/cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stllist.cpp
33 lines (28 loc) · 1.02 KB
/
stllist.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
#include <iostream>
#include <list>
using namespace std;
int main()
{
list<int> a(8, 10); //fills a list 4 places with 10
list<int> mylist(a.begin(), a.end()); //copies a to mylist
list<int>::iterator i;
for (i = mylist.begin(); i != mylist.end(); ++i) //begin and end function works similar to the vector
cout << *i << "\t";
// front and back function also work similar to the vector functions
mylist.pop_front(); //remove from the front of the list
mylist.pop_back(); //remove from the back of the list
mylist.push_front(20); //inserts value to the front of the list
mylist.push_back(30); //insetts value to the back of the list
cout << endl;
for (i = mylist.begin(); i != mylist.end(); ++i)
cout << *i << "\t";
cout << endl;
for (int p = 0; p < 8; p++)
cout << mylist[p] << "\t";
cout << endl;
mylist.sort();
mylist.reverse();
for (i = mylist.begin(); i != mylist.end(); ++i)
cout << *i << "\t";
return 0;
}