Пример #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;

                if (rightChild < currentSize && heapArray[leftChild].ogr.BasariDerecesi < heapArray[rightChild].ogr.BasariDerecesi)
                {
                    largerChild = rightChild;
                }
                else
                {
                    largerChild = leftChild;
                }
                if (top.ogr.BasariDerecesi >= heapArray[largerChild].ogr.BasariDerecesi)
                {
                    break;
                }
                heapArray[index] = heapArray[largerChild];
                index            = largerChild;
            }
            heapArray[index] = top;
        }
Пример #2
0
        public HeapDugumu RemoveMax()
        {
            HeapDugumu root = heapArray[0];

            heapArray[0] = heapArray[--currentSize];
            MoveToDown(0);
            return(root);
        }
Пример #3
0
        public bool Insert(OgrenciBilgi o)
        {
            if (currentSize == maxSize)
            {
                return(false);
            }
            HeapDugumu newHeapDugumu = new HeapDugumu(o);

            heapArray[currentSize] = newHeapDugumu;
            MoveToUp(currentSize++);
            return(true);
        }
Пример #4
0
        public void MoveToUp(int index)
        {
            int        parent = (index - 1) / 2;
            HeapDugumu bottom = heapArray[index];

            while (index > 0 && heapArray[parent].ogr.BasariDerecesi < bottom.ogr.BasariDerecesi)
            {
                heapArray[index] = heapArray[parent];
                index            = parent;
                parent           = (parent - 1) / 2;
            }
            heapArray[index] = bottom;
        }
Пример #5
0
        public HeapDugumu ElemanSil(OgrenciBilgi o)
        {
            int indis = 0;

            for (int i = 0; i < heapArray.Length; i++)
            {
                if (heapArray[i].ogr.ogrenciNo == o.ogrenciNo)
                {
                    indis = i;
                    break;
                }
            }
            HeapDugumu root = heapArray[indis];

            heapArray[indis] = heapArray[--currentSize];
            MoveToDown(indis);
            return(root);
        }