Introduction to queues

Cards (11)

  • A queue is an abstract data type that holds an ordered, linear sequence of items. You can describe it as a first in, first out (FIFO) structure; the first element to be added to the queue will be the first element to be removed from the queue. 
  • New elements are added to the back or rear of the queue.
  • New elements are added to the back or rear of the queue.
  • To keep the order of the queue you need to maintain a pointer to the front, which indicates the element at the front of the queue, and one to the rear, which indicates the element at the back of the queue.
  • A priority queue is one where each element in the queue has a priority. When new elements are added to the queue, they are inserted ahead of those of lower priority and behind elements of equal priority. 
  • Priority queues are useful because they allow us to process tasks based on their importance rather than just their arrival time. For example, in a hospital emergency department, patients who arrive later but require more urgent care may still receive treatment before others who arrived earlier but do not require immediate attention.
  • The enqueue(data) operation can be used to add an element to a queue.
  • The dequeue() method is used to remove an item from the queue.
  • The is_empty() method checks if the queue is empty.
  • The is_full() method checks whether the queue is at maximum capacity (if the size of the queue is constrained).
  • A queue can involve a static or dynamic implementation.