public void MoveToDown(int index) { int SmallerChild; HeapDugumu top = heapArray[index]; while (index < CurrentSize / 2) { int leftChild = 2 * index + 1; int rightChild = leftChild + 1; //Find larger child if (rightChild < CurrentSize && heapArray[leftChild].Data.SatisFiyati < heapArray[rightChild].Data.SatisFiyati) { SmallerChild = leftChild; } else { SmallerChild = rightChild; } if (top.Data.SatisFiyati <= heapArray[SmallerChild].Data.SatisFiyati) { break; } heapArray[index] = heapArray[SmallerChild]; index = SmallerChild; } heapArray[index] = top; }
public HeapDugumu RemoveMin() // Remove maximum value HeapDugumu { HeapDugumu root = heapArray[0]; heapArray[0] = heapArray[--CurrentSize]; MoveToDown(0); return(root); }
public void MoveToUp(int index) { int parent = (index - 1) / 2; HeapDugumu bottom = heapArray[index]; while (index > 0 && heapArray[parent].Data.SatisFiyati > bottom.Data.SatisFiyati) { heapArray[index] = heapArray[parent]; index = parent; parent = (parent - 1) / 2; } heapArray[index] = bottom; }
public bool Insert(Urun Prototip) { if (CurrentSize == MaxSize) { return(false); } HeapDugumu temp = new HeapDugumu(); temp.Data = Prototip; heapArray[CurrentSize] = temp; MoveToUp(CurrentSize++); return(true); }