Created
November 5, 2013 18:42
Revisions
-
JohnTrib3 created this gist
Nov 5, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ MinimumHeap(A){ return A[1]; } ExtractMin(A){ if (heap-size[A] < 1) { then error ``heap underflow'' min <- A[1] A[1] <- A[heap-size[A]] heap-size[A] <- heap-size[A] - 1 } } HeapifyMin(A,1){ return min; } DecreaseKey(A,i,key) if key > A[i]{ then error ``new key is larger than current key'' A[i] <- key } do{ exchange A[i] <-> A[parent(i)]; i <- parent(i); } while (i > 1 && A[parent(i)] > A[i]); MinHeapInsert(A,key){ heap-size[A] <- heap-size[A] + 1 A[heap-size[A]] <- +inf DecreaseKey(A,heap-size[A],key); }