cppreference.com -> C++ Double-Ended Queues -> Details

C++ Double-Ended Queues


Constructors

Syntax:
  deque();
  deque( size_type size );
  deque( size_type num, const TYPE &val );
  deque( const deque &from );
  deque( input_iterator start, input_iterator end );

C++ Deques can be constructed with either:



For example, the following code creates and displays a deque:

  // create a deque with ten '1's in it
  deque<int> dq( 10, 1 );
  // create an iterator
  deque<int>::iterator iter;
  // display the contents of our deque
  for( iter = dq.begin(); iter != dq.end(); iter++ ){ 
    cout << *iter << endl;
  }



Operators

Syntax:
  []

You can access individual members of the double-ended queue using the [] operator.


assign

Syntax:
  void assign( input_iterator start, input_iterator end);
  void assign( Size num, const TYPE &val );

The function assign() sets the double-ended queue the sequence denoted by start and end, or sets num elements to val.


at

Syntax:
  reference at( size_type pos );

The at() function returns a reference to the element at pos in the double-ended queue.


back

Syntax:
  reference back();

The function back() returns a reference to the back element of the double-ended queue.


begin

Syntax:
  iterator begin();

The begin() function returns an iterator to the front element of the double-ended queue.


clear

Syntax:
  void clear();

The clear() function deletes all of the elements from the double-ended queue.


empty

Syntax:
  bool empty();

The function empty() returns true if the double-ended queue is empty, and false otherwise.


end

Syntax:
  iterator end();

The end() function returns an iterator to the back of the double-ended queue.


erase

Syntax:
  iterator erase( iterator pos );
  iterator erase( iterator start, iterator end );

The function erase() erases the element at location pos, or the items between start and end. The return value is an iterator to the element just after the last one erased.


front

Syntax:
  reference front();

The front() function returns a reference to the element at the beginning of the double-ended queue.


get_allocator

Syntax:
  allocator_type get_allocator();

The get_allocator() function returns the double-ended queue's allocator.


insert

Syntax:
  iterator insert( iterator pos, size_type num, const TYPE &val );
  void insert( iterator pos, input_iterator start, input_iterator end );

The insert() function inserts num copies of val before the element at pos, or inserts the sequence specified by start and end before the element at pos.


max_size

Syntax:
  size_type max_size();

The function max_size() returns the maximum number of items that the double-ended queue can hold.


pop_back

Syntax:
  void pop_back();

The pop_back() function removes the last element from the double-ended queue.


pop_front

Syntax:
  void pop_front();

The function pop_front() removes the first element from the double-ended queue.


push_back

Syntax:
  void push_back( const TYPE &val );

The push_back() function adds val to the end of the double-ended queue.


push_front

Syntax:
  void push_front( const TYPE &val );

The function push_front() adds val to the front of the double-ended queue.


rbegin

Syntax:
  reverse_iterator rbegin();

The rbegin() function returns a reverse iterator to the back of the double-ended queue.


rend

Syntax:
  reverse_iterator rend();

The function rend() returns a reverse iterator to the front of the double-ended queue.


resize

Syntax:
  void resize( size_type num, TYPE val );

The resize() function changes the size of the double-ended queue to num, padding any added entries with elements equal to val.


size

Syntax:
  size_type size();

The size() function returns the number of elements in the double-ended queue.


swap

Syntax:
  void swap( deque &target );

The swap() function swaps the elements in the current double-ended queue with those in target.