Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,62 @@
' FB 1.05.0 Win64
' Although it's possible to create generic sorting routines using macros in FreeBASIC
' here we will just use Integer arrays.
Sub quicksort(a() As Integer, first As Integer, last As Integer)
Dim As Integer length = last - first + 1
If length < 2 Then Return
Dim pivot As Integer = a(first + length\ 2)
Dim lft As Integer = first
Dim rgt As Integer = last
While lft <= rgt
While a(lft) < pivot
lft +=1
Wend
While a(rgt) > pivot
rgt -= 1
Wend
If lft <= rgt Then
Swap a(lft), a(rgt)
lft += 1
rgt -= 1
End If
Wend
quicksort(a(), first, rgt)
quicksort(a(), lft, last)
End Sub
Function jortSort(a() As Integer) As Boolean
' copy the array
Dim lb As Integer = LBound(a)
Dim ub As Integer = UBound(a)
Dim b(lb To ub) As Integer
' this could be done more quickly using memcpy
' but we just copy element by element here
For i As Integer = lb To ub
b(i) = a(i)
Next
' sort "b"
quickSort(b(), lb, ub)
' now compare with "a" to see if it's already sorted
For i As Integer = lb To ub
If a(i) <> b(i) Then Return False
Next
Return True
End Function
Sub printResults(a() As Integer)
For i As Integer = LBound(a) To UBound(a)
Print a(i); " ";
Next
Print " => "; IIf(jortSort(a()), "sorted", "not sorted")
End Sub
Dim a(4) As Integer = {1, 2, 3, 4, 5}
printResults(a())
Print
Dim b(4) As Integer = {2, 1, 3, 4, 5}
PrintResults(b())
Print
Print "Press any key to quit"
Sleep