Java Applets Centre
Priority Queue


Description
This applet demonstrates the basic operations on a priority queue (a Min-Heap). The heap structure is restored after both the "insert" and "delete" operations, with the minimum value brought to the root node. Both "insert" and "delete" operations take O(log n) time.


Code (Up-Heap Bubbling)

public void upHeap(int n){
  while(n >1 && a[n]< a[n/2]){
   temp=a[n];
   a[n]=a[n/2];
   a[n/2]=temp;
   n=n/2;
 }
}


Data Structures and Algorithms
Java Applets Centre


R. Mukundan
Department of Computer Science
University of Canterbury
Private Bag 4800, Christchurch
New Zealand.