BBS: Inland Empire Archive Date: 06-08-92 (19:03) Number: 182 From: RICHARD VANNOY Refer#: NONE To: JIM TANNER Recvd: NO Subj: A Better Way 2/3 Conf: (2) Quik_Bas
'Fast modified shell sort implemented by Rich Geldreich.
'Sort algorithm by Dave Cooper.
'May, 1992
'For QB4.5
DEFINT A-Z
CONST True = -1, False = NOT True
DIM A(1000), Pointers(1000)
FOR A = 0 TO 1000
A(A) = RND * 500
Pointers(A) = A
NEXT
A! = TIMER
Low = 0
High = 1000
Mid = (Low + High) \ 2
DO
FOR A = Low TO High - Mid
IF A(Pointers(A)) > A(Pointers(A + Mid)) THEN
SWAP Pointers(A), Pointers(A + Mid)
CompareLow=A - Mid
CompareHigh=A
DO WHILE CompareLow>=Low
IF A(Pointers(CompareLow))>A(Pointers(CompareHigh)) THEN
SWAP Pointers(CompareLow),Pointers(CompareHigh)
CompareHigh = CompareLow
CompareLow = CompareLow-Mid
ELSE
EXIT DO
END IF
LOOP
END IF
NEXT
Mid = Mid \ 2
LOOP WHILE Mid > 0
B! = TIMER
CLS
FOR A = 0 TO 1000
PRINT A(Pointers(A));
NEXT
PRINT : PRINT "sort time *"; B! - A!; "seconds"
* MegaMail 2.1* #0:aibohphobia, n., The fear of palindromes.
---
* Origin: S.D.'s first Wildcat! is now running RA110+ (1:202/307)

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