(12-21-2023, 05:32 PM)mnrvovrfc Wrote:Code: (Select All)ReDim Shared sa$(1 To nItems) 'setup with string array sa$() shared so dont have to pass as parameter
What if the user requires two string arrays to sort, and cannot copy or tamper with the only "sa$()" one?
I'd rather take the example in QB64 Wiki, as slow and clunky as it might look.
https://qb64phoenix.com/qb64wiki/index.php/SWAP
(Example #3 but change array type to string.)
Took me 15 secs to convert to most efficient little bit of sorting code there is:
Code: (Select All)
Sub QSort (Start, Finish, Arr$())
Dim i As Long, j As Long, x$
i = Start
j = Finish
x$ = Arr$(Int((i + j) / 2))
While i <= j
While Arr$(i) < x$
i = i + 1
Wend
While Arr$(j) > x$
j = j - 1
Wend
If i <= j Then
Swap Arr$(i), Arr$(j)
i = i + 1
j = j - 1
End If
Wend
If j > Start Then QSort Start, j, Arr$()
If i < Finish Then QSort i, Finish, Arr$()
End Sub
For Start and Finish use LBound(Arr$) and UBound(Arr$).
b = b + ...