public void MoveToDown(int index) { int largerChild; OtelHeapDugumu top = heapArray[index]; while (index < currentSize / 2) { int leftChild = 2 * index + 1; int rightChild = leftChild + 1; //Find larger child if (rightChild < currentSize && heapArray[leftChild].Deger < heapArray[rightChild].Deger) { largerChild = rightChild; } else { largerChild = leftChild; } if (top.Deger >= heapArray[largerChild].Deger) { break; } heapArray[index] = heapArray[largerChild]; index = largerChild; } heapArray[index] = top; }
public OtelHeapDugumu RemoveMax() // Remove maximum value HeapDugumu { OtelHeapDugumu root = heapArray[0]; heapArray[0] = heapArray[--currentSize]; MoveToDown(0); return(root); }
public bool Insert(int value) { if (currentSize == maxSize) { return(false); } OtelHeapDugumu newHeapDugumu = new OtelHeapDugumu(value); heapArray[currentSize] = newHeapDugumu; MoveToUp(currentSize++); return(true); }
public void MoveToUp(int index) { int parent = (index - 1) / 2; OtelHeapDugumu bottom = heapArray[index]; while (index > 0 && heapArray[parent].Deger < bottom.Deger) { heapArray[index] = heapArray[parent]; index = parent; parent = (parent - 1) / 2; } heapArray[index] = bottom; }