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

Queue

The queue is the first-in-first-out version of the stack. In other words, you add to one end and take off from the other, rather than pushing and popping of the same end. Consider the following code sample:

queue<char> my_Fifo;
my_Fifo.push( 'a' ); // queue contains 'a'
my_Fifo.push( 'b' ); // queue contains 'ab'
my_Fifo.push( 'c' ); // queue contains 'abc'

char cLook = my_Lifo.front(); // cLook contains 'a'
char cLook = my_Lifo.back(); // cLook contains 'c'

char cTake = my_Lifo.pop(); // cTake contains 'a', queue 'bc'

Finally, you have the usual operators for testing emptiness and size. Again, you do not have any other operators for adding to, removing from, sorting, or otherwise indexing the data contained inside the queue.

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