Skip to main content

➡️ Queues

  • The first element to enter, is the first to go out.
  • FIFO (First In, First Out).

Queue Example


🤔 Examples of uses

  • Mail queues
  • Buffers
  • Async function
  • RL example: Real queues, like in a restaurant or a party.

Conditions:

  • size = 0 → empty queue
  • size = queue size → full queue
  • size = 0 && front = -1 && rear = -1 -> Initial state of the queue

Static circular queue

  • The queue size is fixed and is allocated before.
  • The enqueue increments the index of the last element and insert the data in this new index (rear).
  • The dequeue increments the front position (get the next element)
  • If insert value in the last index, we move this new element in the first index (0), instead the last (capacity).

Queue Example


Dynamic queue

  • The queue size is not fixed and we don't have a overflow.
  • We use a node to carry the memory address of the elements.

Queue Example


Deque queue

  • In deque we can insert and delete in the front and the rear.
  • Looks like a structure with 2 queues in a inverse side.

Queue Example