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

int main()
{
  deque<int> d;

  // Output number of values stored in d
  cout << d.size() << endl;

  // Add first 6 integers alternatingly to front and back
  for (int i = 1; i <= 6; i++)
  {
    d.push_front(i++);
    d.push_back(i);
  }

  // Display contents of d from front to back
  for (int i = 0; i < d.size(); i++)
    cout << d[i] << "  ";
  cout << endl;

  // Change back value to 999, remove front value;
  d.back() = 999;
  d.pop_front();

  // Display contents of d again, but use an iterator
  for (deque<int>::iterator it = d.begin();
                  it != d.end(); it++)
    cout << *it << "  ";
  cout << endl;

  // Dump contents of d from back to front
  while (!d.empty())
  {
    cout << d.back() << "  ";
    d.pop_back();
  }
  cout << endl;
}

