Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
(added FreeBasic example) |
m (little change in code) |
||
Line 1,415: | Line 1,415: | ||
' array's can have subscript range from -2147483648 to +2147483647 |
' array's can have subscript range from -2147483648 to +2147483647 |
||
Dim As Integer lb = LBound(bs) |
Dim As Integer lb = LBound(bs) |
||
Dim As Integer ub = UBound(bs) |
Dim As Integer ub = UBound(bs) -1 |
||
Dim As Integer done, i |
Dim As Integer done, i |
||
Do |
Do |
||
done = 0 |
done = 0 |
||
For i = lb To ub |
For i = lb To ub |
||
' replace "<" with ">" for downwards sort |
' replace "<" with ">" for downwards sort |
||
If bs(i) > bs(i + 1) Then |
If bs(i) > bs(i + 1) Then |
||
Line 1,427: | Line 1,427: | ||
End If |
End If |
||
Next |
Next |
||
ub = ub -1 |
|||
Loop Until done = 0 |
Loop Until done = 0 |
||