コード例 #1
0
        public static void Heapify <T>(Func <int, T> get, Action <int, T> set, int i, int count, Comparison <T> comparison)
        {
            int highest = i;

            while (true)
            {
                int left = Heap.Left(i);

                if (left < count && comparison(get(left), get(highest)) > 0)
                {
                    highest = left;
                }

                int right = Heap.Right(i);

                if (right < count && comparison(get(right), get(highest)) > 0)
                {
                    highest = right;
                }

                if (i == highest)
                {
                    return;
                }

                T temp = get(highest);
                set(highest, get(i));
                set(i, temp);

                i = highest;
            }
        }
コード例 #2
0
 public static int Right(int i)
 {
     return(Heap.Left(i) + 1);
 }