Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,65 @@
|
|||
' version 21-10-2016
|
||||
' compile with: fbc -s console
|
||||
' for boundry checks on array's compile with: fbc -s console -exx
|
||||
' converted pseudo code into FreeBASIC code
|
||||
|
||||
' shared variables need to be declared before first use
|
||||
Dim Shared As Long cs(-7 To 7)
|
||||
|
||||
Function circlesort(lo As Long, hi As Long, swaps As ULong) As ULong
|
||||
|
||||
' array is declared shared
|
||||
' sort from lower bound to the highter bound
|
||||
' array's can have subscript range from -2147483648 to +2147483647
|
||||
|
||||
If lo = hi Then Return swaps
|
||||
|
||||
Dim As Long high = hi
|
||||
Dim As Long low = lo
|
||||
Dim As Long mid_ = (hi - lo) \ 2
|
||||
|
||||
While lo < hi
|
||||
If cs(lo) > cs(hi) Then
|
||||
Swap cs(lo), cs(hi)
|
||||
swaps += 1
|
||||
End If
|
||||
lo += 1
|
||||
hi -= 1
|
||||
Wend
|
||||
If lo = hi Then
|
||||
If cs(lo) > cs(hi +1) Then
|
||||
Swap cs(lo), cs(hi +1)
|
||||
swaps += 1
|
||||
End If
|
||||
End If
|
||||
swaps = circlesort(low , low + mid_, swaps)
|
||||
swaps = circlesort(low + mid_ +1, high, swaps)
|
||||
|
||||
Return swaps
|
||||
|
||||
End Function
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
Dim As Long i, a = LBound(cs), b = UBound(cs)
|
||||
|
||||
Randomize Timer
|
||||
For i = a To b : cs(i) = i : Next
|
||||
For i = a To b ' little shuffle
|
||||
Swap cs(i), cs(Int(Rnd * (b - a +1)) + a)
|
||||
Next
|
||||
|
||||
Print "unsorted ";
|
||||
For i = a To b : Print Using "####"; cs(i); : Next : Print
|
||||
|
||||
' sort the array, loop until sorted
|
||||
While circlesort(a, b, 0) : Wend
|
||||
|
||||
Print " sorted ";
|
||||
For i = a To b : Print Using "####"; cs(i); : Next : Print
|
||||
|
||||
' empty keyboard buffer
|
||||
While InKey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue