News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Fast string sort for 32 bit PowerBASIC.

Started by hutch--, September 11, 2017, 02:59:41 PM

Previous topic - Next topic

hutch--

I have had this code since about year 2000 but it was hard to civilise for BASIC programmers until the current releases of PBWIN and PBCC. The attached ZIP file has a batch file to demonstrate the sort and the file for anyone writing PowerBASIC with the current versions to use named "fastsort.bas". It take a basic string in and outputs a basic string that has been sorted using either ascending or descending order. The documentation for the function is at the top of the file.

It is strongly recommended that you do not mess with the guts of the file as its internals are truly complicated and very easy to mess up.

You use it like this by including the "fastsort.bas" file into your own executable code. Note that it will only handle CRLF delimited text source files and should not be used with any other combination. The main sort algorithm is presented in DB format as it is an genuine nightmare to work on in mnemonic form and is best left alone.

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

FUNCTION PBmain as LONG

    src$ = load_file("output.txt")
    StdOut "loaded"

    sorted$ = fastsort(src$,0)   ' ascending sort
    StdOut "sorted"

    save_file("result.txt",sorted$)
    StdOut "done"

End FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


NOTE : I had to re-attach the file after modifying it, I had forgotten to de-allocate the tokenised memory. At the bottom of the "fastsort" function, add this line if you had already downloaded it before.

    GlobalFree parr   ' <<<<<<<<<  HERE

    FUNCTION = buf$                            ' return value is the sorted string

END FUNCTION