Types of Queue


Types of Queues

Types of Queues in Data Structure:


Queue in the data structure is of the following types

  1. Simple Queue
  2. Circular Queue
  3. Priority Queue
  4. Dequeue (Double Ended Queue)


Simple Queue

The simple queue is a normal queue where insertion takes place at the FRONT of the queue and deletion takes place at the END of the queue.


Circular Queue :

  • In a circular queue, the last node is connected to the first node.
  • A circular queue is also called as Ring Buffer.
  • Insertion in a circular queue happens at the FRONT and deletion at the END of the queue.


Priority Queue :

  • In a priority queue, the nodes will have some predefined priority.
  • Insertion in a priority queue is performed in the order of arrival of the nodes.
  • The node having the least priority will be the first to be removed from the priority queue.


Dequeue (Double Ended Queue) :

In a Double Ended Queue, insertion and deletion operations can be done at both FRONT and END of the queue.

Basic operations in a queue

The most basic queue operations in the data structure are the following

  • enqueue() - Adds an element at the beginning of the queue. If the queue is full, then it is an overflow.
  • dequeue() - Deletes an element at the end of the queue. If the queue is empty, then it is an underflow.

enqueue() 

    1. Check if the queue is full.
    2. If the queue is full, then print "Queue overflow".
    3. Else increment REAR by 1.
    4. Assign QUEUE [ REAR ] = ELEMENT.

dequeue()

    1. Check if the queue is empty.
    2. If the queue is empty, the print "Queue underflow".
    3. Copy the element at the front of the queue to some temporary variable, TEMP = QUEUE[ FRONT ].
    4. Increment FRONT by 1. 
    5. Print temp and delete it.

Post a Comment

0 Comments