예제 #1
0
        public void MoveToDown(int index)
        {
            int           largerChild;
            urunHeapDugum 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.satisFiyat < heapArray[rightChild].Deger.satisFiyat)
                {
                    largerChild = rightChild;
                }
                else
                {
                    largerChild = leftChild;
                }
                if (top.Deger.satisFiyat >= heapArray[largerChild].Deger.satisFiyat)
                {
                    break;
                }
                heapArray[index] = heapArray[largerChild];
                index            = largerChild;
            }
            heapArray[index] = top;
        }
예제 #2
0
        public urunHeapDugum RemoveMax() // Remove maximum value HeapDugumu
        {
            urunHeapDugum root = heapArray[0];

            heapArray[0] = heapArray[--currentSize];
            MoveToDown(0);
            return(root);
        }
예제 #3
0
        public bool Insert(urun value)
        {
            if (currentSize == maxSize)
            {
                return(false);
            }
            urunHeapDugum newHeapDugumu = new urunHeapDugum(value);

            heapArray[currentSize] = newHeapDugumu;
            MoveToUp(currentSize++);
            return(true);
        }
예제 #4
0
        public void MoveToUp(int index)
        {
            int           parent = (index - 1) / 2;
            urunHeapDugum bottom = heapArray[index];

            while (index > 0 && heapArray[parent].Deger.satisFiyat < bottom.Deger.satisFiyat)
            {
                heapArray[index] = heapArray[parent];
                index            = parent;
                parent           = (parent - 1) / 2;
            }
            heapArray[index] = bottom;
        }