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 tox
.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 toy
.empty()
: Returns a Boolean value indicating whether the queue is empty or not. For example,bool b = myQueue.empty()
will assigntrue
tob
if the queue is empty, andfalse
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 tos
.
Note that front()
, back()
, empty()
, and size()
methods are also available for other sequence containers in the STL, such as vectors and deques.