Esempio n. 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].otel.YildizSayisi < heapArray[rightChild].otel.YildizSayisi)
                {
                    largerChild = rightChild;
                }
                else
                {
                    largerChild = leftChild;
                }
                if (top.otel.YildizSayisi >= heapArray[largerChild].otel.YildizSayisi)
                {
                    break;
                }
                heapArray[index] = heapArray[largerChild];
                index            = largerChild;
            }
            heapArray[index] = top;
        }
Esempio n. 2
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 && decimal.Parse(heapArray[leftChild].otel.OtelPuani) < decimal.Parse(heapArray[rightChild].otel.OtelPuani))
                {
                    largerChild = rightChild;
                }
                else
                {
                    largerChild = leftChild;
                }
                if (decimal.Parse(top.otel.OtelPuani) >= decimal.Parse(heapArray[largerChild].otel.OtelPuani))
                {
                    break;
                }
                heapArray[index] = heapArray[largerChild];
                index            = largerChild;
            }
            heapArray[index] = top;
        }
Esempio n. 3
0
        public HeapDugumu RemoveMax() // Remove maximum value HeapDugumu
        {
            HeapDugumu root = heapArray[0];

            heapArray[0] = heapArray[--currentSize];
            MoveToDown(0);
            return(root);
        }
Esempio n. 4
0
        public bool Insert(Otel otel)
        {
            if (currentSize == maxSize)
            {
                return(false);
            }
            HeapDugumu newHeapDugumu = new HeapDugumu(otel);

            heapArray[currentSize] = newHeapDugumu;
            MoveToUp(currentSize++);
            return(true);
        }
Esempio n. 5
0
        public void MoveToUp(int index)
        {
            int        parent = (index - 1) / 2;
            HeapDugumu bottom = heapArray[index];

            while (index > 0 && heapArray[parent].otel.YildizSayisi < bottom.otel.YildizSayisi)
            {
                heapArray[index] = heapArray[parent];
                index            = parent;
                parent           = (parent - 1) / 2;
            }
            heapArray[index] = bottom;
        }
Esempio n. 6
0
        public void MoveToUp(int index)
        {
            int        parent = (index - 1) / 2;
            HeapDugumu bottom = heapArray[index];

            while (index > 0 && decimal.Parse(heapArray[parent].otel.OtelPuani) < decimal.Parse(bottom.otel.OtelPuani))
            {
                heapArray[index] = heapArray[parent];
                index            = parent;
                parent           = (parent - 1) / 2;
            }
            heapArray[index] = bottom;
        }