home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
QBAS
/
BAS_SORT.ZIP
/
RIPLSORT.SUB
< prev
next >
Wrap
Text File
|
1989-07-15
|
6KB
|
114 lines
DECLARE SUB RiplSort (Ar$(), Elements%)
' ********************************************************************************
' ** Name: RiplSort **
' ** Type: SubProgram **
' ** Lang: MS-QuickBASIC or BASICA **
' ** Author: Mike Welch **
' ** Purpose: A really fast BASIC sort **
' ** History: Mike Shaffer (of Dallas) first introduced me to his **
' ** modification of the Mentat sort (ripple sort) by answering **
' ** a request for help in creating a fast QB sort. After finding **
' ** a copy of the MNTSORT itself, I made the necessary changes to **
' ** make the program truly structured. (The original contained 15+ **
' ** GOTO's and line labels). This sort is the end result of **
' ** 25 + hours of work. I think that it will prove to be the **
' ** fastest STRUCTURED sort for a BASIC program. My thanks to **
' ** both Mike Shaffer and Richard F. Ashwell III, author of the **
' ** MNTSORT (Mentat) sort. Yes friends, it blows the Qsort away. **
' ** Other: This particular rendition of the ripple sort is Copywrited (C) **
' ** <7/1989> for one reason: I have worked too hard on the algorithim**
' ** and especially the 'structurization' process to have someone **
' ** publish it in a magazine as his own work and receive a fee. **
' ** (I'm in college and if anybody needs money it's me). Otherwise, **
' ** This routine is FREE to whomever cares to use it. As you can **
' ** probably tell it is written for Microsoft's (C) QuickBASIC **
' ** compiler. However, with modification it could surely be used **
' ** in BASIC(a) as well. I invite your comments and improvements. **
' ** Keep the SHAREWARE idea alive by sending comments/improvements. **
' ** Coore: Send comments to: Mike Welch: PO Box 401011: Dallas, TX 75243. **
' ** Finals: Original author's address (a software company) below: **
' ** Mentat Software: Richard F. Ashwell III: 1830 Dover Rd.: Dover **
' ** Florida: 33527 **
' ********************************************************************************
'
'
SUB RiplSort (Ar$(), Elements%) STATIC
' Dimension array variables and initialize
DIM Plane%(1000), Wave%(1000)
CONST FALSE% = 0, TRUE% = NOT FALSE%
Y% = Elements%
' Begin the sort routine
DReg% = 1
EReg% = 1
Plane%(DReg%) = 1
Wave%(DReg%) = Y%
AReg% = Y%
DO
DO
EndLoop% = TRUE%
IF (AReg% - EReg%) < 9 THEN
IF (AReg% - EReg%) = 0 THEN
EReg% = Plane%(DReg%)
AReg% = Wave%(DReg%)
DReg% = DReg% - 1
IF DReg% = 0 THEN
' < Sort ends here >
' < so erase the markers >
ERASE Plane%, Wave%
EXIT SUB
ELSE
EndLoop% = FALSE%
END IF
END IF
IF EndLoop% = TRUE% THEN
FOR BReg% = (EReg% + 1) TO AReg%
FOR CReg% = EReg% TO (BReg% - 1)
FReg% = BReg% - CReg% + EReg% - 1
IF NOT Ar$(FReg%) <= Ar$(FReg% + 1) THEN
SWAP Ar$(FReg%), Ar$(FReg% + 1)
END IF
NEXT CReg%
NEXT BReg%
END IF
END IF
LOOP UNTIL EndLoop% = TRUE%
BReg% = EReg%
CReg% = AReg%
DO
IF Ar$(BReg%) > Ar$(CReg%) THEN
SWAP Ar$(CReg%), Ar$(BReg%)
DO
BReg% = BReg% + 1
IF CReg% > BReg% THEN
IF Ar$(CReg%) < Ar$(BReg%) THEN
SWAP Ar$(CReg%), Ar$(BReg%)
EXIT DO
END IF
ELSE
EXIT DO
END IF
LOOP
END IF
CReg% = CReg% - 1
LOOP WHILE CReg% > BReg%
CReg% = CReg% + 1
DReg% = DReg% + 1
IF (BReg% - EReg%) < (AReg% - CReg%) THEN
Plane%(DReg%) = CReg%
Wave%(DReg%) = AReg%
AReg% = BReg%
ELSE
Plane%(DReg%) = EReg%
Wave%(DReg%) = BReg%
EReg% = CReg%
END IF
LOOP
END SUB