-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path43_listSTL.cpp
46 lines (40 loc) · 935 Bytes
/
43_listSTL.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
// Array : used when acces needs faster
// LInked list : used when insertion/deletion is faster ( unidirectional)
// LIst : It is bi-directional
#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);
display(list1);
list1.pop_back();
list1.pop_front();
display(list1);
list1.remove(5); // It remove a specified element
display(list1);
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;
display(list2);
return 0;
}