Sorting algorithms/Heapsort: Difference between revisions

(added perl)
Line 898:
Output:
<pre>0 1 2 3 4 5 6 7 8 9</pre>
 
=={{header|TI-83 BASIC}}==
Store list with a dimension of 7 or less into L<sub>1</sub> (if less input will be padded with zeros), run prgmSORTHEAP, look into L<sub>2</sub> for the sorted version of L<sub>1</sub>. It is possible to do this without L<sub>3</sub>, but I coded this when I was paying attention to a math lecture.
:If dim(L<sub>1</sub>)>7
:Then
:Disp "ERR:7"
:Stop
:End
:If dim(L<sub>1</sub>)<7
:Then
:For(A,1,7)
:If A>dim(L<sub>1</sub>)
:0→L<sub>1</sub>(A)
:End
:End
:{0}→L<sub>2</sub>
:For(B,2,7)
:0→L<sub>2</sub>(B)
:End
:L<sub>1</sub>→L<sub>3</sub>
:For(B,0,6)
:If L<sub>3</sub>(4)>L<sub>3</sub>(2)
:Then
:L<sub>3</sub>(2)→A
:L<sub>3</sub>(4)→L<sub>3</sub>(2)
:A→L<sub>3</sub>(4)
:End
:If L<sub>3</sub>(5)>L<sub>3</sub>(2)
:Then
:L<sub>3</sub>(2)→A
:L<sub>3</sub>(5)→L<sub>3</sub>(2)
:A→L<sub>3</sub>(5)
:End
:If L<sub>3</sub>(6)>L<sub>3</sub>(3)
:Then
:L<sub>3</sub>(3)→A
:L<sub>3</sub>(6)→L<sub>3</sub>(3)
:A→L<sub>3</sub>(6)
:End
:If L<sub>3</sub>(7)>L<sub>3</sub>(3)
:Then
:L<sub>3</sub>(3)→A
:L<sub>3</sub>(7)→L<sub>3</sub>(3)
:A→L<sub>3</sub>(7)
:End
:If L<sub>3</sub>(2)>L<sub>3</sub>(1)
:Then
:L<sub>3</sub>(1)→A
:L<sub>3</sub>(2)→L<sub>3</sub>(1)
:A→L<sub>3</sub>(2)
:End
:If L<sub>3</sub>(3)>L<sub>3</sub>(1)
:Then
:L<sub>3</sub>(1)→A
:L<sub>3</sub>(3)→L<sub>3</sub>(1)
:A→L<sub>3</sub>(3)
:End
:L<sub>3</sub>(1)→L<sub>2</sub>(7-B)
:If L<sub>3</sub>(2)>L<sub>3</sub>(3)
:Then
:L<sub>3</sub>(2)→L<sub>3</sub>(1)
:0→L<sub>3</sub>(2)
:Else
:L<sub>3</sub>(3)→L<sub>3</sub>(1)
:0→L<sub>3</sub>(3)
:End
:End
:DelVar A
:DelVar B
:DelVar L<sub>3</sub>
:Stop
Anonymous user