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; }
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; }