开发者

Heap Sorting Algorithm

开发者 https://www.devze.com 2022-12-15 13:21 出处:网络
I need the algorithm of HeapSort for sorting the elements of the array,开发者_如何学JAVA such that all the elements of the array i.e [19 18 14 15 5 7 13 3 8] are in non-decreasing order.Read about Hea

I need the algorithm of HeapSort for sorting the elements of the array,开发者_如何学JAVA such that all the elements of the array i.e [19 18 14 15 5 7 13 3 8] are in non-decreasing order.


Read about Heapsort here. A nice pseudocode has also been provided.


Heapsort is pretty simple. You grab all elements, put them in a heap (in your case, a max-heap) in any order and then grab them back from the heap (with the delete-max operation) and they come all sorted up.


Actually, you can use IF-free (branchless) heap sort

0

精彩评论

暂无评论...
验证码 换一张
取 消