Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alphabetizing Anyone?
#11
(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 + ...
Reply


Messages In This Thread
Alphabetizing Anyone? - by NakedApe - 12-20-2023, 05:42 PM
RE: Alphabetizing Anyone? - by SMcNeill - 12-20-2023, 06:17 PM
RE: Alphabetizing Anyone? - by NakedApe - 12-20-2023, 08:20 PM
RE: Alphabetizing Anyone? - by bplus - 12-20-2023, 09:53 PM
RE: Alphabetizing Anyone? - by NakedApe - 12-21-2023, 05:27 PM
RE: Alphabetizing Anyone? - by mnrvovrfc - 12-21-2023, 05:32 PM
RE: Alphabetizing Anyone? - by bplus - 12-21-2023, 09:42 PM
RE: Alphabetizing Anyone? - by SMcNeill - 02-25-2024, 03:24 AM
RE: Alphabetizing Anyone? - by SpriggsySpriggs - 12-21-2023, 06:02 PM
RE: Alphabetizing Anyone? - by TerryRitchie - 12-21-2023, 06:08 PM
RE: Alphabetizing Anyone? - by SpriggsySpriggs - 12-21-2023, 07:46 PM
RE: Alphabetizing Anyone? - by NakedApe - 12-21-2023, 08:06 PM



Users browsing this thread: 4 Guest(s)