C++ Queue Methods

Once you have created a Queue in C++, you can use the following methods to manipulate it:

  • push(): Adds an element to the back of the queue. For example, myQueue.push(10) adds the value 10 to the back of the queue.

  • pop(): Removes the element at the front of the queue. For example, myQueue.pop() removes the first element in the queue.

  • front(): Returns the element at the front of the queue. For example, int x = myQueue.front() will assign the value of the first element in the queue to x.

  • back(): Returns the element at the back of the queue. For example, int y = myQueue.back() will assign the value of the last element in the queue to y.

  • empty(): Returns a Boolean value indicating whether the queue is empty or not. For example, bool b = myQueue.empty() will assign true to b if the queue is empty, and false otherwise.

  • size(): Returns the number of elements in the queue. For example, int s = myQueue.size() will assign the number of elements in the queue to s.

Note that front(), back(), empty(), and size() methods are also available for other sequence containers in the STL, such as vectors and deques.