|
|
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; } } |