Queue

Created


Queue is another limited access ADT that supports

  • enqueue: adds element to the data structure
  • dequeue: removes the least recently added element not yet removed.
  • front: peeks at the front value without removing it
  • empty: checks if it is empty.
  • FIFO: first in, first out is the order that elements are removed.

Array Implementation

Two variables front and back act as pointers. When the back varaible reaches the end of the array, it will wrap around it to the "front" fo the array, creating a circular array. Use % length trick to reset the index when it reaches the length of the array .

Dynamically grow the array when the back reaches front.

Other Restricted Data Structures

  • Steque ADT is a stack-ended queue that supports push, pop, and enque.
  • Quack ADT is a queue-ended queue that supports push, pop, and dequeue.
  • Dequeue ADT is a double ended queue that allows insertion/removal at either end in O(1).
    • Many programming languages include an implementation of dequeue that can operate as a stack or queue.