/    /  Data Structures-Queue Operations

Queue Operations

 

Basic queue operations are as follows:

  1. enqueue()
  2. dequeue()
  3. peek()
  4. isFull()
  5. isEmpty()

 

Enqueue()

It adds an item to the queue.

It does so by following the below steps:

  1. It first checks if the queue is full.
  2. If it is full, it produces overflow and exits. 
  3. If it is not, then it increments the rear pointer to point at the next empty space.
  4. Then an element is added to the empty space.
  5. It returns success.

The algorithm:

 

Dequeue 

It removes an item from the queue. 

It follows the following steps:

  1. Firstly, it checks if the queue is empty.
  2. If it is empty it produces an overflow error and exits.
  3. If it is not then it accesses the data where the front pointer points.
  4. Then it increments the front pointer. 
  5. Finally, it returns success.

The algorithm:

 

Peek()

It gets the element to the front of the queue.

The algorithm:

 

isFull()

It checks if the queue is full.

The algorithm:

 

isEmpty()

It checks if the queue is empty.

The algorithm:

Reference

Queue Operations