Queues are container adaptors that store elements in a first-in-first-out (FIFO) order. Elements inserted into the queue first are removed first.
#include <queue> queue<type> queueName;
type is the data type that will be stored in the queue.
The following codebyte example creates an empty queue, adds elements using the
.push() method, and then prints the elements from the queue:
- Checks if a queue has no elements.
- Returns the next element within the queue.
- Removes the element at the front of the queue.
- Adds an element to the back of the queue.
- Returns the number of elements in the queue.
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
Learn C++ on Codecademy
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification