O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deque

The deque, or double-ended queue, is an array that’s constructed in the same way as a vector and uses many of its same functions and operators. The deque can determine the array’s size, resize it, and empty it. In addition, deque defines functions to obtain an indexed value—deque::at( int nIndex)—and offers the same front and back operators as a vector.

You can add to the deque at the front or back, as the name suggests. You can also remove from the front or back of the deque. Assume that have defined a deque as follows:

deque<char> my_string ( 10, '.' ) ; // a string of 10 x '.'

Given this new string definition, you can then use the push operations as follows:

my_string.push_front ( 'a' ); // add an 'a' to the front my_string.push_back ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required