Article 110 - Priority Queue Implementation

A Priority Queue is often implemented using a heap for best performance.

To program a Priority Queue, we need to understand the interface of a Priority Queue.

Interface

  • Enqueue Node
  • Dequeue Node

Implementation

In this implementation, we use the Heap structure from Article 109 - Heap Implementation.

Enqueue Node Function

Add a node in the proper spot. This is a wrapper function that calls the Heap's function to add an entry.

int enqueue( Node ** heap, int priority, int content ){
    return addNode( heap, priority, content );
}

Dequeue Node Function

Removes the head node and find new head node. This is a wrapper function that calls the Heap's function to get the minimum entry.

int dequeue( Node ** heap, int * priority, int * content ){
    return getTop( heap, priority, content );
}

Comments (0)

Post a comment

  • Name:
  • Post:
  • Challenge:

Register or login to post comments easier.


Vantasy World Copyright 2011 - 2017. Vantasy World is a project developed by Vantasy Online. Privacy Policy.