Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
(Sorting algorithms/Bubble sort in True BASIC)
Line 1,301: Line 1,301:
dim list[size]
dim list[size]


gosub fill
let index = 0
gosub sort
gosub show
do


end
let list[index] = int: (rnd) * 100


sub fill
let index = index + 1


loop index < size
for index = 0 to size - 1


let list[index] = int: (rnd) * 100
do
print index


next index
let sort = 0


return
let index = 0

sub sort


do
do


let temp1 = index + 1
let sort = 0
for index = 0 to size - 2

let temp1 = index + 1


if list[index] > list[temp1] then
if list[index] > list[temp1] then


let temp2 = list[index]
let temp2 = list[index]
let list[index] = list[temp1]
let list[index] = list[temp1]
let list[temp1] = temp2
let list[temp1] = temp2
let sort = 1
let sort = 1


endif
endif


let index = index + 1
next index


wait
loop index < size - 1


loop sort = 1
wait


return
loop sort = 1


sub show
let index = 0


for index = 0 to size - 1
do


print index ," : ", list[index]
print index ," : ", list[index]


let index = index + 1
next index


loop index < size</syntaxhighlight>
return</syntaxhighlight>


==={{header|FreeBASIC}}===
==={{header|FreeBASIC}}===