Exemplo n.º 1
0
void heapUp(int i) {
    int origValue = heap[i];
    while (i > 0 && currentMin[origValue] < currentMin[heap[heapParent(i)]]) {
        heap[i] = heap[heapParent(i)];
        heapPos[heap[i]] = i;
        i = heapParent(i);
    }
    heap[i] = origValue;
    heapPos[origValue] = i;
}
Exemplo n.º 2
0
bool isBinaryHeap(const Heap& h)
{
    const auto first = h.begin();
    const auto n = h.size();
    const auto comp = h.compare();

    for( auto i = n > 0 ? n - 1 : 0; i > 0; --i ) {
        const auto parent = heapParent(i);
        if( comp(*(first + parent), *(first + i)) ) {
            qWarning() << "Heap property violated at" << i << "( size" << n << ")";
            return false;
        }
    }

    return true;
}