3.12. Using a Queue in C++ΒΆ

Now we will turn our attention to using the queue data structure with the help of the Standard Template Library (STL) in C++.

As we described in Chapter 1, in C++, as in any object-oriented programming language, the implementation of choice for an abstract data type such as a queue is a class in which the queue operations are implemented as methods. Fortunately, the STL already has a well written implementation of the queue class.

In following queue implementation (ActiveCode 1) as push operations occur, new items are always added on the rear end of the queue and pop operations will manipulate the opposite side, the front end.

Self Check

Before you keep reading...

Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.

You have attempted 1 of 4 activities on this page