Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alphabetizing Anyone?
#8
When I have a small list of strings to sort I usually use this simple bubble sort. It's not fast but with small arrays of strings it's not even noticeable.

Code: (Select All)
'simple bubble sort

DIM Outer AS LONG '             outer loop counter
DIM Inner AS LONG '             inner loop counter
DIM StringList(100) AS STRING ' an array of strings

FOR Outer = 1 TO UBOUND(StringList) - 1 '                                   loop array size-1
    FOR Inner = 1 TO UBOUND(stringlist) - Outer '                           loop remaining indexes
        IF UCASE$(StringList(Inner)) > UCASE$(StringList(Inner + 1)) THEN ' is next index smaller?
            SWAP StringList(Inner), StringList(Inner + 1) '                 yes, swap indexes (bubble up)
        END IF
    NEXT Inner
NEXT Outer
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
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: 5 Guest(s)