Sorting algorithms/Bubble sort: Difference between revisions
m
→{{header|FreeBASIC}}: minor change
m (→{{header|FreeBASIC}}: removed redundant code) |
m (→{{header|FreeBASIC}}: minor change) |
||
Line 1,410:
=={{header|FreeBASIC}}==
Per task pseudo code:
<lang FreeBASIC>' version 21-
' compile with: fbc -s console
' for boundry checks on array's compile with: fbc -s console -exx
Sub bubblesort(bs() As
' sort from lower bound to the highter bound
' array's can have subscript range from -2147483648 to +2147483647
Dim As
Dim As
Dim As
Do
done = 0
For i = lb To ub -1
' replace "<" with ">" for downwards sort
If bs(i) > bs(i +
Swap bs(i), bs(i +
done = 1
End If
Next
Loop Until done = 0
Line 1,437 ⟶ 1,436:
' ------=< MAIN >=------
Dim As
Dim As
Randomize Timer
For i = a To b : array(i) = i : Next
For i = a To b ' little shuffle
Swap array(i), array(Int(Rnd * (b - a +1)) + a)
Next
Line 1,459 ⟶ 1,458:
End</lang>
{{out}}
<pre>unsort -7
sort -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7</pre>
|