Anonymous user
Sorting algorithms/Insertion sort: Difference between revisions
Sorting algorithms/Insertion sort (view source)
Revision as of 15:32, 30 October 2012
, 11 years agoBBC BASIC solution updated
(→{{header|REXX}}: changed DO loop indentations, changed comments, added comments, changed fence, re-order subroutines in alphbetical order. -- ~~~~) |
(BBC BASIC solution updated) |
||
Line 191:
=={{header|BBC BASIC}}==
Note that the array index is assumed to start at zero.
<lang bbcbasic> DIM test(9)
FOR I%=2 TO Size%▼
test() = 4, 65, 2, -31, 0, 99, 2, 83, 782, 1
PROCinsertionsort(test(), 10)
FOR i% = 0 TO 9
WHILE J%>1 AND Temp%<data%(J%-1)▼
END
DEF PROCinsertionsort(a(), n%)
ENDPROC</lang>▼
LOCAL i%, j%, t
t = a(i%)
j% = i%
a(j%) = a(j%-1)
j% -= 1
ENDWHILE
a(j%) = t
NEXT
▲ ENDPROC</lang>
'''Output:'''
<pre>
-31 0 1 2 2 4 65 83 99 782
</pre>
=={{header|C}}==
|