stl:deque:push_front

C++ Reference

push_front

Syntax:

    #include <deque>
    void push_front( const TYPE& val );

The push_front function inserts val at the beginning of the deque.

push_front runs in constant time.

For example, the following code uses push_front to insert several doubles into a deque, and then uses the copy algorithm to display the deque:

  deque<double> values;
  ostream_iterator<double> output( cout, " " );
 
  values.push_front( 2.2 );
  values.push_front( 3.5 );
  values.push_back( 1.1 );
 
  cout << "values contains: ";
  for( size_t i = 0; i < values.size(); ++i ) cout << values[i] << ' ';
  cout << '\n';
 
  values.pop_front();      // remove first element
  cout << "After pop_front, values contains: ";
  copy( values.begin(), values.end(), output );
  cout << '\n';
 
  values[1] = 5.4;
  cout << "Now values contains: ";
  copy( values.begin(), values.end(), output );
  cout << '\n';

Related Topics: assign, front, insert, pop_front, push_back