Sorting algorithms/Comb sort: Difference between revisions

added FreeBasic
m (Added the Sidef language)
(added FreeBasic)
Line 597:
end program Combsort_Demo</lang>
=={{header|FreeBASIC}}==
<lang FreeBASIC>' version 05-07-2015
' compile with: fbc -s console
' for boundry checks on array's compile with: fbc -s console -exx
 
Sub compsort(bs() As Integer)
' sort from lower bound to the highter bound
' array's can have subscript range from -2147483648 to +2147483647
Dim As Integer lb = LBound(bs)
Dim As Integer ub = UBound(bs)
Dim As Integer gap = ub - lb
Dim As Integer done, i
 
Do
gap = Int (gap / 1.3)
If gap < 1 Then gap = 1
done = 0
For i = lb To ub - gap
If bs(i) > bs(i + gap) Then
Swap bs(i), bs(i + gap)
done = 1
End If
Next
Loop Until ((gap = 1) And (done = 0))
 
End Sub
 
' ------=< MAIN >=------
 
Dim As Integer i, array(-7 To 8)
 
Dim As Integer a = LBound(array), b = UBound(array) -1
 
Randomize Timer
For i = a To b : array(i) = i : Next
For i = a To b ' little shuffle
Swap array(i), array(Rnd * (b - a) + a)
Next
 
b = b + 1
 
Print "normal comb sort"
Print "unsorted ";
For i = a To b : Print Using "####"; array(i); : Next : Print
compsort(array()) ' sort the array
Print " sorted ";
For i = a To b : Print Using "####"; array(i); : Next : Print
 
' empty keyboard buffer
While Inkey <> "" : Var _key_ = Inkey : Wend
Print : Print "hit any key to end program"
Sleep
End</lang>
{{out}}
<pre>normal comb sort
unsorted -1 3 -4 -6 -7 2 7 -3 1 4 0 -5 -2 5 6 0
sorted -7 -6 -5 -4 -3 -2 -1 0 0 1 2 3 4 5 6 7</pre>
 
=={{header|Go}}==
<lang go>package main
457

edits