public void MaxHeapifyUp(Heap <int> A, int i, int key) { while (i > 1 && key > A[A.Parent(i)]) { A[i] = A[A.Parent(i)]; i = A.Parent(i); } A[i] = key; }
public void IncreaseKey(Heap <int> A, int i, int key) { if (key < A[i]) { throw new Exception("key is too small"); } A[i] = key; while (i > 1 && A[i] > A[A.Parent(i)]) { int temp = A[i]; A[i] = A[A.Parent(i)]; A[A.Parent(i)] = temp; i = A.Parent(i); } }
public bool Verify(Heap <int> A) { for (int i = A.HeapSize; i > 1; i--) { if (A[i] > A[A.Parent(i)]) { return(false); } } return(true); }