public void ChangeMax(int newValue) { HeapNode data = arr[0]; arr[0].Value = newValue; HeapifyDown(0); }
public void Heapify(List <int> num, int n) { arr = new HeapNode[n]; for (int i = 0; i < n; i++) { arr[i] = new HeapNode { Value = num[i], Index = i }; } count = n; for (int i = (count - 1) / 2; i >= 0; i--) { HeapifyDown(i); } }
public void HeapifyDown(int pos) { int l = GetLeftChild(pos); int r = GetRightChild(pos); int max = pos; if (l != -1 && arr[max].Value < arr[l].Value) { max = l; } if (r != -1 && arr[max].Value < arr[r].Value) { max = r; } if (max != pos) { HeapNode temp = arr[pos]; arr[pos] = arr[max]; arr[max] = temp; HeapifyDown(max); } }