Home » CEEFAX disks » telesoftware1.adl » General/FQSORT

General/FQSORT

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » CEEFAX disks » telesoftware1.adl
Filename: General/FQSORT
Read OK:
File size: 0370 bytes
Load address: 0000
Exec address: 0000
File contents
23470REM *****************************
23480REM *                           *
23490REM *   Quicksort Routine       *
23500REM *    J. Meers  1986         *
23510REM * Prestel Mailbox 707327277 *
23520REM *                           *
23530REM *****************************
23540:
23550REM Quicksort Routine
23560DEF PROCqsort(n%):LOCAL t$,t%,m$,rp%
23570PROCQsort(0,n%):ENDPROC
23580:
23590DEF PROCQsort(l%,r%):IF r%-l%>1 THEN 23610
23600IF K$(l%)>K$(r%) THEN PROCswap(l%,r%):ENDPROC:ELSE ENDPROC
23610LOCAL lp%:lp%=l%-1:rp%=r%+1:m$=K$((l%+r%)DIV 2):REPEAT
23620REPEAT:lp%=lp%+1:UNTIL K$(lp%)>=m$
23630REPEAT:rp%=rp%-1:UNTIL K$(rp%)<=m$
23640IF lp%<rp% THEN PROCswap(lp%,rp%)
23650UNTIL lp%>=rp%
23660PROCQsort(l%,rp%):PROCQsort(lp%,r%)
23670ENDPROC
23680:
23690DEF PROCswap(a%,b%)
23700t$=K$(a%):K$(a%)=K$(b%):K$(b%)=t$
23710t%=p%(a%):p%(a%)=p%(b%):p%(b%)=t%
23720ENDPROC
23730:
00000000  32 33 34 37 30 52 45 4d  20 2a 2a 2a 2a 2a 2a 2a  |23470REM *******|
00000010  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
00000020  2a 2a 2a 2a 2a 2a 0d 32  33 34 38 30 52 45 4d 20  |******.23480REM |
00000030  2a 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |*               |
00000040  20 20 20 20 20 20 20 20  20 20 20 20 2a 0d 32 33  |            *.23|
00000050  34 39 30 52 45 4d 20 2a  20 20 20 51 75 69 63 6b  |490REM *   Quick|
00000060  73 6f 72 74 20 52 6f 75  74 69 6e 65 20 20 20 20  |sort Routine    |
00000070  20 20 20 2a 0d 32 33 35  30 30 52 45 4d 20 2a 20  |   *.23500REM * |
00000080  20 20 20 4a 2e 20 4d 65  65 72 73 20 20 31 39 38  |   J. Meers  198|
00000090  36 20 20 20 20 20 20 20  20 20 2a 0d 32 33 35 31  |6         *.2351|
000000a0  30 52 45 4d 20 2a 20 50  72 65 73 74 65 6c 20 4d  |0REM * Prestel M|
000000b0  61 69 6c 62 6f 78 20 37  30 37 33 32 37 32 37 37  |ailbox 707327277|
000000c0  20 2a 0d 32 33 35 32 30  52 45 4d 20 2a 20 20 20  | *.23520REM *   |
000000d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000000e0  20 20 20 20 20 20 20 20  2a 0d 32 33 35 33 30 52  |        *.23530R|
000000f0  45 4d 20 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |EM *************|
00000100  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
00000110  0d 32 33 35 34 30 3a 0d  32 33 35 35 30 52 45 4d  |.23540:.23550REM|
00000120  20 51 75 69 63 6b 73 6f  72 74 20 52 6f 75 74 69  | Quicksort Routi|
00000130  6e 65 0d 32 33 35 36 30  44 45 46 20 50 52 4f 43  |ne.23560DEF PROC|
00000140  71 73 6f 72 74 28 6e 25  29 3a 4c 4f 43 41 4c 20  |qsort(n%):LOCAL |
00000150  74 24 2c 74 25 2c 6d 24  2c 72 70 25 0d 32 33 35  |t$,t%,m$,rp%.235|
00000160  37 30 50 52 4f 43 51 73  6f 72 74 28 30 2c 6e 25  |70PROCQsort(0,n%|
00000170  29 3a 45 4e 44 50 52 4f  43 0d 32 33 35 38 30 3a  |):ENDPROC.23580:|
00000180  0d 32 33 35 39 30 44 45  46 20 50 52 4f 43 51 73  |.23590DEF PROCQs|
00000190  6f 72 74 28 6c 25 2c 72  25 29 3a 49 46 20 72 25  |ort(l%,r%):IF r%|
000001a0  2d 6c 25 3e 31 20 54 48  45 4e 20 32 33 36 31 30  |-l%>1 THEN 23610|
000001b0  0d 32 33 36 30 30 49 46  20 4b 24 28 6c 25 29 3e  |.23600IF K$(l%)>|
000001c0  4b 24 28 72 25 29 20 54  48 45 4e 20 50 52 4f 43  |K$(r%) THEN PROC|
000001d0  73 77 61 70 28 6c 25 2c  72 25 29 3a 45 4e 44 50  |swap(l%,r%):ENDP|
000001e0  52 4f 43 3a 45 4c 53 45  20 45 4e 44 50 52 4f 43  |ROC:ELSE ENDPROC|
000001f0  0d 32 33 36 31 30 4c 4f  43 41 4c 20 6c 70 25 3a  |.23610LOCAL lp%:|
00000200  6c 70 25 3d 6c 25 2d 31  3a 72 70 25 3d 72 25 2b  |lp%=l%-1:rp%=r%+|
00000210  31 3a 6d 24 3d 4b 24 28  28 6c 25 2b 72 25 29 44  |1:m$=K$((l%+r%)D|
00000220  49 56 20 32 29 3a 52 45  50 45 41 54 0d 32 33 36  |IV 2):REPEAT.236|
00000230  32 30 52 45 50 45 41 54  3a 6c 70 25 3d 6c 70 25  |20REPEAT:lp%=lp%|
00000240  2b 31 3a 55 4e 54 49 4c  20 4b 24 28 6c 70 25 29  |+1:UNTIL K$(lp%)|
00000250  3e 3d 6d 24 0d 32 33 36  33 30 52 45 50 45 41 54  |>=m$.23630REPEAT|
00000260  3a 72 70 25 3d 72 70 25  2d 31 3a 55 4e 54 49 4c  |:rp%=rp%-1:UNTIL|
00000270  20 4b 24 28 72 70 25 29  3c 3d 6d 24 0d 32 33 36  | K$(rp%)<=m$.236|
00000280  34 30 49 46 20 6c 70 25  3c 72 70 25 20 54 48 45  |40IF lp%<rp% THE|
00000290  4e 20 50 52 4f 43 73 77  61 70 28 6c 70 25 2c 72  |N PROCswap(lp%,r|
000002a0  70 25 29 0d 32 33 36 35  30 55 4e 54 49 4c 20 6c  |p%).23650UNTIL l|
000002b0  70 25 3e 3d 72 70 25 0d  32 33 36 36 30 50 52 4f  |p%>=rp%.23660PRO|
000002c0  43 51 73 6f 72 74 28 6c  25 2c 72 70 25 29 3a 50  |CQsort(l%,rp%):P|
000002d0  52 4f 43 51 73 6f 72 74  28 6c 70 25 2c 72 25 29  |ROCQsort(lp%,r%)|
000002e0  0d 32 33 36 37 30 45 4e  44 50 52 4f 43 0d 32 33  |.23670ENDPROC.23|
000002f0  36 38 30 3a 0d 32 33 36  39 30 44 45 46 20 50 52  |680:.23690DEF PR|
00000300  4f 43 73 77 61 70 28 61  25 2c 62 25 29 0d 32 33  |OCswap(a%,b%).23|
00000310  37 30 30 74 24 3d 4b 24  28 61 25 29 3a 4b 24 28  |700t$=K$(a%):K$(|
00000320  61 25 29 3d 4b 24 28 62  25 29 3a 4b 24 28 62 25  |a%)=K$(b%):K$(b%|
00000330  29 3d 74 24 0d 32 33 37  31 30 74 25 3d 70 25 28  |)=t$.23710t%=p%(|
00000340  61 25 29 3a 70 25 28 61  25 29 3d 70 25 28 62 25  |a%):p%(a%)=p%(b%|
00000350  29 3a 70 25 28 62 25 29  3d 74 25 0d 32 33 37 32  |):p%(b%)=t%.2372|
00000360  30 45 4e 44 50 52 4f 43  0d 32 33 37 33 30 3a 0d  |0ENDPROC.23730:.|
00000370
General/FQSORT.m0
General/FQSORT.m1
General/FQSORT.m2
General/FQSORT.m4
General/FQSORT.m5