//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;
}