[go: up one dir, main page]

0% found this document useful (0 votes)
2 views1 page

STL 03 List-01.cpp

Uploaded by

rockyyyy884
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

STL 03 List-01.cpp

Uploaded by

rockyyyy884
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

//Lists are sequence containers that allow non-contiguous memory allocation.

// As compared to vector, the list has slow traversal,


//but once a position has been found, insertion and deletion are quick.

#include <stdio.h>
#include <iterator>
#include <list>
using namespace std;

// function for printing the elements in a list


void showlist(list<int> g)
{
//using scope resolution(::)
list<int>::iterator it;
printf("\n");
for (it = g.begin(); it != g.end(); ++it)
printf("%d ",*it);

// Driver Code
int main()
{

list<int> list1, list2 = {3,15,9, 18,6,12, 27,24,21, 30};

for (int i = 1; i <= 10; ++i)


{ list1.push_back(i * 2);
// list2.push_front(i * 3);
}
printf("\nList 1 (list1) is : ");
showlist(list1);

printf("\nList 2 (list2) is : ");


showlist(list2);

printf("\nlist1.front() : %d",list1.front());
printf( "\nlist1.back() : %d",list1.back());
//
list1.pop_front(); // pop one element to front
list1.pop_front();
showlist(list1);
//
printf("\nlist2.pop_back() : ");
list2.pop_back();
showlist(list2);
//
printf("\n\nlist1.reverse() : ");
list1.reverse();
showlist(list1);
//
printf("\nlist1.sort(): ");
list2.sort();
showlist(list1);

return 0;
}

You might also like