this is a beginner work and I'd like te have a heap which contains any item inserted by me. However, when I insert the values, if I delete the min value of this coded heap twice, I get the min value uncorrect.I could not find where the mistake is. Could you please help me?
void BinaryHeap::percolateDown(int hole) {
for (int child = hole * 2; child < size; hole++, child = hole * 2) {
if (heap[hole] > heap[child]) {
this->swap(hole, child); // give index rather than value
}
if (heap[hole] > heap[child + 1]) {
this->swap(hole, child + 1); //give it index rather than value
}
}
}