Re: string sorting

 BBS: Inland Empire Archive
Date: 11-21-92 (11:21)             Number: 375
From: DIK COATES                   Refer#: NONE
  To: JOHN GALLAS                   Recvd: NO  
Subj: Re: string sorting             Conf: (2) Quik_Bas
>>>> QUOTING Joe Clark to John Gallas <<<<

 JC> If you are looking for a basic sorting routine, then the
 JC> fastest that I have used is the "SHELL-METZNER SORT"

Enclosed for your edification:

'***************************************************** SUBPROGRAM Sortshell.1
'
'   Procedure uses the Shell-Metzger algorithm for sorting an array of string
'   variables.  Adapted from an article by Donald Shell.  This sorting
'   algorithm is extremely efficient for sorting small and medium sized
'   arrays.
'
'   PARAMETERS: col0% = number of elements in the string array array$()
'               array$() = string variable array to be sorted.
'   RETURNS:    array$() = sorted string variable array
'
'   REV:        88-04-01
'
SUB Sortshell.1 (col0%, array$())
    col1% = col0%

    WHILE col1% <> 0
        col1% = col1% \ 2
        col2% = col0% - col1%

        FOR count% = 1 TO col2%
            col3% = count%
sort1:
            col4% = col3% + col1%

            IF array$(col3%) <= array$(col4%) THEN
                GOTO sort2
            ELSE
                SWAP array$(col3%), array$(col4%)
                col3% = col3% - col1%
            END IF

            IF col3% > 0 THEN
                GOTO sort1
            END IF
sort2:
        NEXT count%
    WEND
END SUB


Was cooked from original assembly code from IBM mainframe back when
I was young and foolish...It is fast, but for random generated strings.
If the list is partially sorted (or only 1 element out of place, as
common for database stuff, then old bubble sort is by far the fastest)

Regards Dik

... Vote Conservative or I'll shoot your dog. -Dik
___ Blue Wave/QWK v2.10

--- Maximus 2.00
 * Origin: Durham Systems (ONLINE!) (1:229/110)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET