I need the algorithm of HeapSort for sorting the elements of the array, such that all the elements of the array i.e [19 18 14 15 5 7 13 3 8] are in non-decreasing order.
-
In what programmin language you need it?Branislav Abadjimarinov– Branislav Abadjimarinov2010-01-03 12:07:16 +00:00Commented Jan 3, 2010 at 12:07
-
It is okay to ask here, but wikipedia usually has very good articles on algorithms.R. Martinho Fernandes– R. Martinho Fernandes2010-01-03 12:17:15 +00:00Commented Jan 3, 2010 at 12:17
-
1"Non-decreasing" as in "increasing"?spender– spender2010-01-03 12:29:06 +00:00Commented Jan 3, 2010 at 12:29
Add a comment
|
3 Answers
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.