Just like a stack, a queue is a linear data structure. The difference is that whereas a stack utilizes “last in, first out” operations (LIFO), a queue operates according to a “first in, first out” pattern (FIFO). This is very much like a line at a deli, where the first customer in line gets served first.
The basic operations of a queue are:
- Enqueue — places a new element at the back (or “tail”) of the queue
- Dequeue — retrieves the element at the queue’s front (or “head”)
isEmpty() to check if the queue is empty.
Now we can create our own queue, and enqueue/dequeue elements (in this case: dog names).