コード例 #1
0
        private void MoveToDownPuan(int index)
        {
            int        largerChild;
            HeapDugumu top = heapArrayPuan[index];

            while (index < currentSize / 2)
            {
                int leftChild  = 2 * index + 1;
                int rightChild = leftChild + 1;

                if (rightChild < currentSize && heapArrayPuan[leftChild].otel.OtelPuani < heapArrayPuan[rightChild].otel.OtelPuani)
                {
                    largerChild = rightChild;
                }
                else
                {
                    largerChild = leftChild;
                }
                if (top.otel.OtelPuani >= heapArrayPuan[largerChild].otel.OtelPuani)
                {
                    break;
                }
                heapArrayPuan[index] = heapArrayPuan[largerChild];
                index = largerChild;
            }
            heapArrayPuan[index] = top;
        }
コード例 #2
0
        public HeapDugumu RemoveMax()
        {
            HeapDugumu root = heapArrayPuan[0];

            heapArrayPuan[0] = heapArrayPuan[--currentSize];
            MoveToDownPuan(0);
            return(root);
        }
コード例 #3
0
        public bool InsertOtel(OtelBilgi o)
        {
            if (currentSize == maxSize)
            {
                return(false);
            }
            HeapDugumu newHeapDugumu = new HeapDugumu(o);

            heapArrayPuan[currentSize] = newHeapDugumu;
            MoveToUpPuan(currentSize++);
            return(true);
        }
コード例 #4
0
        private void MoveToUpPuan(int index)
        {
            int        parent = (index - 1) / 2;
            HeapDugumu bottom = heapArrayPuan[index];

            while (index > 0 && heapArrayPuan[parent].otel.OtelPuani < bottom.otel.OtelPuani)
            {
                heapArrayPuan[index] = heapArrayPuan[parent];
                index  = parent;
                parent = (parent - 1) / 2;
            }
            heapArrayPuan[index] = bottom;
        }
コード例 #5
0
        public HeapDugumu ElemanSil(OtelBilgi otel)
        {
            int indis = 0;

            for (int i = 0; i < heapArrayPuan.Length; i++)
            {
                if (heapArrayPuan[i].otel.OtelID == otel.OtelID)
                {
                    indis = i;
                    break;
                }
            }
            HeapDugumu root = heapArrayPuan[indis];

            heapArrayPuan[indis] = heapArrayPuan[--currentSize];
            MoveToDownPuan(indis);
            return(root);
        }