push_front [C++ Reference]
Keywords: stl,deque,push_front
Date: 2008-11-14T16:54:09-0800

[[push_front]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## 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

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •