private void growHeap() { capacity = (capacity * 2) + 1; HeapEntry <T>[] newHeap = new HeapEntry <T> [capacity]; System.Array.Copy(heap, 0, newHeap, 0, count); heap = newHeap; }
private void bubbleUp(int index, HeapEntry <T> he) { int parent = (index - 1) / 2; // note: (index > 0) means there is a parent while ((index > 0) && (heap[parent].Priority > he.Priority)) { heap[index] = heap[parent]; index = parent; parent = (index - 1) / 2; } heap[index] = he; }
private void trickleDown(int index, HeapEntry <T> he) { int child = (index * 2) + 1; while (child < count) { if (((child + 1) < count) && (heap[child].Priority > heap[child + 1].Priority)) { child++; } heap[index] = heap[child]; index = child; child = (index * 2) + 1; } bubbleUp(index, he); }