Beispiel #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;
        }
Beispiel #2
0
        public HeapDugumu RemoveMax() // Remove maximum value HeapDugumu
        {
            HeapDugumu root = heapArray[0];

            heapArray[0] = heapArray[--currentSize];
            MoveToDown(0);
            return(root);
        }
Beispiel #3
0
        public static void RemoveMax()
        {
            HeapDugumu max = h.RemoveMax();

            Console.WriteLine("ADIM 3 - Max eleman ({0}) Heap'ten silindi....\n", max.Deger);
            h.DisplayHeap();
            Console.ReadLine();
        }
Beispiel #4
0
 public int[] Sort()
 {
     for (int i = 0; i < dizi.Length; i++)
     {
         HeapDugumu max = heap.RemoveMax(); //remove metodu hem maxı veriyor hem de maxı sildiği için kullandım
         dizi[i] = max.Deger;               //dizimdeki elemanları Heap ağacına eklemiştim tekrar dizime ekledim
     }
     return(dizi);
 }
Beispiel #5
0
        public bool Insert(int value)
        {
            if (currentSize == maxSize)
            {
                return(false);
            }
            HeapDugumu newHeapDugumu = new HeapDugumu(value);

            heapArray[currentSize] = newHeapDugumu;
            MoveToUp(currentSize++);
            return(true);
        }
Beispiel #6
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;
        }