Queue Data Structure


A queue is another list-type data structure and (in this case) an extension of a doubly linked list. The defining trait of a queue is that insertion only happens at the end (last node) and deletion only happens at the front (first node). The queue employs a First In First Out (FIFO) structure, meaning the order that nodes are enqueued will be the order that they are read from. This is the opposite structure of a Stack. A practical use of a queue would be an application where people are waiting in line, because the people first in line are the first people to be served. Queues are also used when downloading multiple games at once, for example. Since games usually only download one at a time, they are put in a queue that downloads them one after the other.


Below is a basic implementation of a queue in C++. We implement it using a doubly linked list and with three main functions:

  • Enqueue - Add a node to the end of the queue

  • Dequeue - Remove and return the node at the front of the queue

  • Peek - Return the value of the front node but don't remove it