Sorting algorithms/Heapsort: Difference between revisions

Added PicoLisp
(Added PicoLisp)
Line 1,174:
Output = 1 2 3 4 5 6 7 8 9
</pre>
 
=={{header|PicoLisp}}==
<lang PicoLisp>(de heapSort (A Cnt)
(let Cnt (length A)
(for (Start (/ Cnt 2) (gt0 Start) (dec Start))
(siftDown A Start (inc Cnt)) )
(for (End Cnt (> End 1) (dec End))
(xchg (nth A End) A)
(siftDown A 1 End) ) )
A )
 
(de siftDown (A Start End)
(use Child
(for (Root Start (> End (setq Child (* 2 Root))))
(and
(> End (inc Child))
(> (get A (inc Child)) (get A Child))
(inc 'Child) )
(NIL (> (get A Child) (get A Root)))
(xchg (nth A Root) (nth A Child))
(setq Root Child) ) ) )</lang>
Output:
<pre>: (heapSort (make (do 9 (link (rand 1 999)))))
-> (1 167 183 282 524 556 638 891 902)</pre>
 
=={{header|PureBasic}}==
Anonymous user