Beispiel #1
0
        internal void Enqueue(T element, double priority)
        {
            if (heapSize == A.Length - 1)
            {
                var newA = new GenericHeapElement <T> [A.Length * 2];
                Array.Copy(A, 1, newA, 1, heapSize);
                A = newA;
            }

            heapSize++;
            int i = heapSize;

            A[i] = cache[element] = new GenericHeapElement <T>(i, priority, element);
            while (i > 1 && A[i >> 1].priority.CompareTo(priority) > 0)
            {
                SwapWithParent(i);
                i >>= 1;
            }
        }
Beispiel #2
0
 void PutAtI(int i, GenericHeapElement <T> h)
 {
     A[i]       = h;
     h.indexToA = i;
 }