'===========================================================================
' Subject: SHELL SORT SUBROUTINE              Date: 06-22-98 (22:10)       
'  Author: Douglas Bunger                     Code: QB, QBasic, PDS        
'  Origin: www.public.usit.net/dbunger/..   Packet: ALGOR.ABC
'===========================================================================
DEFINT A-Z
'======================================
SUB ShellSort (a$(), number, direction)
'======================================
' number = items in array to be sorted
'          (first item must be #1)
' direction = 0 for ascending
'             1 for decending
'

offset = number \ 2
DO WHILE offset > 0: limit = number - offset
   DO: switch = 0
      FOR row = 0 TO limit: doit = 0
         IF direction = 0 THEN
            IF a$(row) > a$(row + offset) THEN doit = 1
         ELSE
            IF a$(row) < a$(row + offset) THEN doit = 1
         END IF
         IF doit = 1 THEN SWAP a$(row), a$(row + offset): switch = row
      NEXT row: limit = switch - offset
   LOOP WHILE switch: offset = offset \ 2
LOOP
END SUB
