Max heap in o(n) implementation

not getting the correct output for this case.

@guptashubham210a
I am not understanding your doubt. The heap has been constructed properly. All the parent nodes are greater than their child nodes. Can you please elaborate your query?

@LP18Aug0068
it should print in order na?

@LP18Aug0068
for this input 55
1
99
0
2
output should be 99 55 2 1 0 na

@guptashubham210a
You are mistaken. A heap is not a sorted array. It outputs elements in a sorted array. A max heaps property is that all the child nodes of a node are smaller than the parent nodes. The children are represented by 2i and 2i + 1. In the previous output, you can clearly see that the property holds out.

If my answer is able to resolve your query, please mark the doubt as resolved.