Example #1
0
        public void percolateDown(int i)
        {
            int x = heap[i];

            while (left(i) < heap.size())
            {
                int child = right(i) < heap.size() && comp(heap[right(i)], heap[left(i)]) ? right(i) : left(i);
                if (!comp(heap[child], x))
                {
                    break;
                }
                heap[i]          = heap[child];
                indices[heap[i]] = i;
                i = child;
            }
            heap   [i] = x;
            indices[x] = i;
        }
Example #2
0
 public bool ok(int n)
 {
     return(n >= 0 && n < (int)indices.size());
 }