Demonstrating the difference between push_back() and push_front() : list push pop « list « C++ Tutorial






#include <iostream>
#include <list>
using namespace std;

int main()
{
  list<int> lst1, lst2;
  int i;

  for(i=0; i<10; i++) lst1.push_back(i);
  for(i=0; i<10; i++) lst2.push_front(i);
  
  list<int>::iterator p;
  
  cout << "Contents of lst1:\n";
  p = lst1.begin();  
  while(p != lst1.end()) {
    cout << *p << " ";
    p++;
  }
  cout << "\n\n";

  cout << "Contents of lst2:\n";
  p = lst2.begin();  
  while(p != lst2.end()) {
    cout << *p << " ";
    p++;
  }
    
  return 0;
}
Contents of lst1:
0 1 2 3 4 5 6 7 8 9

Contents of lst2:
9 8 7 6 5 4 3 2 1 0








17.11.list push pop
17.11.1.list: push_back and push_front
17.11.2.list: push_back, front, empty and pop_front
17.11.3.Add some data by push_front
17.11.4.Demonstrating the difference between push_back() and push_front()
17.11.5.list.pop_front(): remove element from front
17.11.6.difference between push_back() and push_front()
17.11.7.list.pop_back(): remove element from back