Sorting algorithms/Insertion sort: Difference between revisions

{{header|Liberty BASIC}}
(GP)
({{header|Liberty BASIC}})
Line 788:
lst insertionSortInPlace println # ==> list(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
</lang>
 
=={{header|Liberty BASIC}}==
<lang lb> itemCount = 20
dim A(itemCount)
for i = 1 to itemCount
A(i) = int(rnd(1) * 100)
next i
 
print "Before Sort"
gosub [printArray]
 
'--- Insertion sort algorithm
for i = 2 to itemCount
value = A(i)
j = i-1
while j >= 0 and A(j) > value
A(j+1) = A(j)
j = j-1
wend
A(j+1) = value
next
'--- end of (Insertion sort algorithm)
 
print "After Sort"
gosub [printArray]
end
 
[printArray]
for i = 1 to itemCount
print using("###", A(i));
next i
print
return</lang>
 
=={{header|Lua}}==
Anonymous user