Heap sort for elements

but at the end result is not sorted then what is the use if elements are not going to be in sorted order

for obtaining a sorted array, let’s use a min heap and create that heap and now remove n elmeents one by one from the heap and keep storing them into a new array. Thats’s how you get the sorted array. Obviously, it takes O(n logn ) time, which is actually the best you can do to sort an array of elements.