Priority Queue in C Programming

Priority Queue in C Programming 

A priority Queue in C Programming  data structure is a special type of queue in which deletion and insertion perform on the basis of priority of data element.There can be min priority queue and max priority queue.In real word example when a VIP comes for a service he will get the service before the other people standing in a Queue because he has the priority over other people.

Priority Queue

More About Priority Queue in C Programming

  • Priority Queue is the special case of Queue.
  • In priority queue deletion and insertion base on priority of the data elements 
  • In Queue there is priority for each element.
  • There is two types of Priority Queue min priority queue and max priority queue.
  • In min priority queue min number has highest priority and max number has lowest priority.In max priority queue max number has highest priority and min number has lowest priority.
  • Priority Queue can be implemented using Array, Linked list and Heap in C programming language.

Priority Queue operations

  • Enqueue(): Adding a new item to the Queue Data Structure, in other words Enqueue new item to Queue If Queue is full, then it is said to be in an overflow condition.
  • Dequeue(): Delete a item from a Queue, Deletion based on priority, highest priority element deleted first.In other words Dequeue item from Queue If queue is empty then it is said to be in an underflow condition.
  • Print(): Print the data elements of Queue.

Implementation of Priority Queue in C Programming

Priority Queue can be implemented by three data Structure:-

  • Array
  • Linked List
  • Heap

Operations on Priority Queue

There is three operations we can perform on Priority Queue as follows:

  • Enqueue()
  • Dequeue()
  • Print()
  • isEmpty()
Operation on priority queue

1.Enqueue( )

  • When we require to add an element and its priority to the queue we perform Enqueue() operation.
  • Enqueue() operation is synonymous of insertion in a data structure Queue.

2.Dequeue()

  • When we require to delete an element and its priority from the queue we perform Dequeue() operation.
  • Dequeue() operation is synonymous of deletion in a data structure Queue.
Enqueue Operartion
Dequeue operarion

3.Print( )

  • Print() function is use to print the data and priority of data of Queue

4.isEmpty( )

  • isEmpty() function is use to check,Queue is empty or not.
Print operation
C Program for implementing isEmpty() in a queue

Applications of Priority Queue

There is following applications of Priority Queue:

  • Dijktra’s shortest path algorithm.
  • Prim’s Algorithm
  • Data Compression->Huffman Code
  • Heap Sort
  • Operating System: Local Balancing, Interrupt Handling.

Queue using Array

Here we have already learned implementation of Queues using Linked List in C , click the button below to learn the implementation of queue using array