private void MoveToDownPuan(int index) { int largerChild; HeapDugumu top = heapArrayPuan[index]; while (index < currentSize / 2) { int leftChild = 2 * index + 1; int rightChild = leftChild + 1; if (rightChild < currentSize && heapArrayPuan[leftChild].otel.OtelPuani < heapArrayPuan[rightChild].otel.OtelPuani) { largerChild = rightChild; } else { largerChild = leftChild; } if (top.otel.OtelPuani >= heapArrayPuan[largerChild].otel.OtelPuani) { break; } heapArrayPuan[index] = heapArrayPuan[largerChild]; index = largerChild; } heapArrayPuan[index] = top; }
public HeapDugumu RemoveMax() { HeapDugumu root = heapArrayPuan[0]; heapArrayPuan[0] = heapArrayPuan[--currentSize]; MoveToDownPuan(0); return(root); }
public bool InsertOtel(OtelBilgi o) { if (currentSize == maxSize) { return(false); } HeapDugumu newHeapDugumu = new HeapDugumu(o); heapArrayPuan[currentSize] = newHeapDugumu; MoveToUpPuan(currentSize++); return(true); }
private void MoveToUpPuan(int index) { int parent = (index - 1) / 2; HeapDugumu bottom = heapArrayPuan[index]; while (index > 0 && heapArrayPuan[parent].otel.OtelPuani < bottom.otel.OtelPuani) { heapArrayPuan[index] = heapArrayPuan[parent]; index = parent; parent = (parent - 1) / 2; } heapArrayPuan[index] = bottom; }
public HeapDugumu ElemanSil(OtelBilgi otel) { int indis = 0; for (int i = 0; i < heapArrayPuan.Length; i++) { if (heapArrayPuan[i].otel.OtelID == otel.OtelID) { indis = i; break; } } HeapDugumu root = heapArrayPuan[indis]; heapArrayPuan[indis] = heapArrayPuan[--currentSize]; MoveToDownPuan(indis); return(root); }