void deleteNode(vector& heap,int i)
{
heap[i]=INT_MAX;
upHeapify(heap,i);
swap(heap[0],heap[heap.size()-1]);
downHeapify(heap,0);
}
Where I am going wrong in my code?
Getting wrong output
your approach is absolutely fine. but to spot any error, i need to check your whole code.
can you please post complete code.
thanks
after swapping the node, you forgot to delete it from vector.
void deleteNode(vector& heap,int i)
{
heap[i]=INT_MAX;
upHeapify(heap,i);
swap(heap[0],heap[heap.size()-1]);
heap.pop_back(); --------------> remove from heap
downHeapify(heap,0);
}
thanks