示例#1
0
        public void MoveToDown(int index)
        {
            int        largerChild;
            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].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;
        }
示例#2
0
        public HeapDugumu RemoveMax() // Remove maximum value HeapDugumu
        {
            HeapDugumu root = heapArray[0];

            heapArray[0] = heapArray[--currentSize];
            MoveToDown(0);
            heapArray.Remove(heapArray[currentSize]);
            return(root);
        }
示例#3
0
        public void MoveToUp(int index)
        {
            int        parent = (index - 1) / 2;
            HeapDugumu bottom = heapArray[index];

            while (index > 0 && heapArray[parent].Deger < bottom.Deger)
            {
                heapArray[index] = heapArray[parent];
                index            = parent;
                parent           = (parent - 1) / 2;
            }
            heapArray[index] = bottom;
        }
示例#4
0
        public bool Insert(Kisi eklenecekKisi)
        {
            foreach (HeapDugumu heapDugumu in heapArray)
            {
                if (heapDugumu != null)
                {
                    if (heapDugumu.kisi == eklenecekKisi)
                    {
                        return(false);
                    }
                }
            }
            HeapDugumu newHeapDugumu = new HeapDugumu(eklenecekKisi);

            heapArray.Add(newHeapDugumu);
            MoveToUp(currentSize++);
            return(true);
        }