Demonstrate push_front(), front(), pop_front() on list - C++ STL

C++ examples for STL:list

Description

Demonstrate push_front(), front(), pop_front() on list

Demo Code

#include <iostream>
#include <list>
using namespace std;
int main()/*from w  ww . java 2  s  .c  om*/
{
   list<int> ilist;
   ilist.push_back(30);              // push items on back
   ilist.push_back(40);
   ilist.push_front(20);             // push items on front
   ilist.push_front(10);
   int size = ilist.size();          // number of items
   for(int j=0; j<size; j++)
   {
      cout << ilist.front() << ' ';  // read item from front
      ilist.pop_front();             // pop item off front
   }
   cout << endl;
   return 0;
}

Result


Related Tutorials