- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hello! (Wave)
I tried to write an algorithm that heapifies a min-heap..
That's what I have tried:
Could you tell me if it is right? (Thinking)
I tried to write an algorithm that heapifies a min-heap..
That's what I have tried:
Code:
MIN_HEAPIFY(A,i){
left=2*i;
right=2*i+1;
smallest=i;
if (left<=length(A) and A[left]<A[smallest]) smallest=left;
if (right<=length(A) and A[right]<A[smallest]) smallest=right;
if (smallest!=i){
swap(A[i],A[smallest]) ;
MIN_HEAPIFY(A,i);
}
}
Could you tell me if it is right? (Thinking)