-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStdList.cpp
More file actions
40 lines (35 loc) · 975 Bytes
/
Copy pathStdList.cpp
File metadata and controls
40 lines (35 loc) · 975 Bytes
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
//list template class
//list STL
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <list>
using namespace std;
int main()
{
system("cls");
list <int>list1{10,20,30};
list <string> list2{"rahul","rohit","ruby","sonam"};
// accessing list using iterator
list <int>::iterator p = list1.begin(); //creating a pointer for list
while(p !=list1.end())
{
cout<<*p<<endl;
p++;
}
//size method
cout<<"Total value in list1 "<<list1.size()<<endl;
cout<<"Total value in list2 "<<list2.size()<<endl;
//push method inserting value in list at last index
list2.push_back("Deepika");
list2.push_front("Sanjay");
cout<<"After pushing element in list2"<<endl;
list <string>::iterator p1 = list2.begin(); //creating a pointer for list
while(p1 !=list2.end())
{
cout<<*p1<<endl;
p1++;
}
cout<<"Total value in list2 "<<list2.size()<<endl;
system("pause");
}