-
Notifications
You must be signed in to change notification settings - Fork 2
/
37.cpp
36 lines (32 loc) · 802 Bytes
/
37.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
#include<iostream>
#include<list>
int main()
{
//understanding the end() function
//when we call end() func. we get the reference to the end()-1th element
std::list<int> lt;
//inserting some elements
for(int i=0;i<10;i++)
{
lt.push_back(i);
}
//printing the list in forward direction
std::list<int>::iterator p = lt.begin();
std::cout<<"List : ";
while(p!=lt.end())
{
std::cout<<*p<<" ";
p++;
}
std::cout<<std::endl;
//printing the list in the backward direction
p = lt.end();
std::cout<<"List : ";
while(p!=lt.begin())
{
p--; //decrementing so that p should first point to the last element
std::cout<<*p<<" ";
}
std::cout<<std::endl;
return 0;
}