Beispiel #1
0
 private void growHeap()
 {
     this.capacity = (this.capacity * 2) + 1;
     HeapEntry[] newHeap = new HeapEntry[this.capacity];
     System.Array.Copy(heap, 0, newHeap, 0, count);
     heap = newHeap;
 }
Beispiel #2
0
        private void bubbleUp(int index, HeapEntry he)
        {
            int parent = (index - 1) / 2;

            // note: (index > 0) means there is a parent
            while ((index > 0) && (heap[parent].Priority.CompareTo(he.Priority) < 0))
            {
                this.heap[index] = this.heap[parent];
                index            = parent;
                parent           = (index - 1) / 2;
            }
            heap[index] = he;
        }
Beispiel #3
0
        private void trickleDown(int index, HeapEntry he)
        {
            int child = (index * 2) + 1;

            while (child < count)
            {
                if (((child + 1) < count) &&
                    (this.heap[child].Priority.CompareTo(this.heap[child + 1].Priority) < 0))
                {
                    child++;
                }
                this.heap[index] = this.heap[child];
                index            = child;
                child            = (index * 2) + 1;
            }
            bubbleUp(index, he);
        }
 private void trickleDown(int index, HeapEntry he)
 {
     int child = (index * 2) + 1;
     while (child < count)
     {
         if (((child + 1) < count) &&
             (this.heap[child].Priority.CompareTo(this.heap[child + 1].Priority)<0))
         {
             child++;
         }
         this.heap[index] = this.heap[child];
         index = child;
         child = (index * 2) + 1;
     }
     bubbleUp(index, he);
 }
 private void growHeap()
 {
     this.capacity = (this.capacity * 2) + 1;
     HeapEntry[] newHeap = new HeapEntry[this.capacity];
     System.Array.Copy(heap, 0, newHeap, 0, count);
     heap = newHeap;
 }
 private void bubbleUp(int index, HeapEntry he)
 {
     int parent = (index - 1) / 2;
     // note: (index > 0) means there is a parent
     while ((index > 0) && (heap[parent].Priority.CompareTo(he.Priority)<0))
     {
         this.heap[index] = this.heap[parent];
         index = parent;
         parent = (index - 1) / 2;
     }
     heap[index] = he;
 }