Valami készül

private void siftDown(int i)
{
     var swapWith = i;
     if (2 * i + 1 < heapCount)
     {
         if (2 * i + 2 < heapCount)
         {
             if (array[i].CompareTo(array[2 * i + 2]) < 0 &&
                 array[2 * i + 1].CompareTo(array[2 * i + 2]) < 0)
                 swapWith = 2 * i + 2;
             else
                 if (array[i].CompareTo(array[2 * i + 1]) < 0)
                     swapWith = 2 * i + 1;
         }
         else
             if (array[i].CompareTo(array[2 * i + 1]) < 0)
                 swapWith = 2 * i + 1;
     }
     if (i == swapWith)
         return;
     swap(i, swapWith);
     if (lacksHeapProperty(swapWith))
         siftDown(swapWith);
}

A teljes algoritmust és a hozzá tartozó programot hamarosan közzé teszem. (Gondolom, ennek hatására olvasóimat most a várakozás-vágyakozás eksztatikus érzése keríti hatalmába, de hát ez van.)

Leave a Comment

Your email address will not be published. Required fields are marked *