示例#1
0
 private void growHeap()
 {
     capacity = (capacity * 2) + 1;
     HeapEntry2 <T>[] newHeap = new HeapEntry2 <T> [capacity];
     System.Array.Copy(heap, 0, newHeap, 0, count);
     heap = newHeap;
 }
示例#2
0
        private void bubbleUp(int index, HeapEntry2 <T> he)
        {
            int parent = (index - 1) / 2;

            // note: (index > 0) means there is a parent
            while ((index > 0) && (heap[parent].Item.CompareTo(he.Item) > 0)) //This is a potential place for bugs, this started as: heap[parent].Priority > he.Priority
            {
                heap[index] = heap[parent];
                index       = parent;
                parent      = (index - 1) / 2;
            }
            heap[index] = he;
        }
示例#3
0
        private void trickleDown(int index, HeapEntry2 <T> he)
        {
            int child = (index * 2) + 1;

            while (child < count)
            {
                if (((child + 1) < count) &&
                    (heap[child].Item.CompareTo(heap[child + 1].Item) > 0)) //Started out as: heap[child].Priority > heap[child + 1].Priority
                {
                    child++;
                }
                heap[index] = heap[child];
                index       = child;
                child       = (index * 2) + 1;
            }
            bubbleUp(index, he);
        }