Jump to content

Sorting algorithms/Insertion sort: Difference between revisions

Sorting algorithms/Insertion sort in BASIC256
No edit summary
(Sorting algorithms/Insertion sort in BASIC256)
Line 1,620:
350 NEXT
360 END DEF</syntaxhighlight>
 
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic">global array
dim array(15)
a = array[?,]
b = array[?]
for i = a to b-1
array[i] = int(rand * 100)
next i
 
print "unsort ";
for i = a to b-1
print rjust(array[i], 4);
next i
 
call insertionSort(array) # ordenar el array
 
print chr(10); " sort ";
for i = a to b-1
print rjust(array[i], 4);
next i
end
 
subroutine insertionSort(array)
lb = array[?,]
 
for i = lb + 1 to array[?]-1
valor = array[i]
j = i - 1
while j >= lb and array[j] > valor
array[j +1] = array[j]
j -= 1
end while
 
array[j+1] = valor
next i
end subroutine</syntaxhighlight>
 
=={{header|BCPL}}==
2,136

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.