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

General/FQSORTT

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/FQSORTT
Read OK:
File size: 0D19 bytes
Load address: 0000
Exec address: 0000
File contents
     DISC NUMBER :                                DISC CATEGORY : SORT
                                                  FILENAME : F.QSORT-T
     
     
     MACHINE                       BBC B/B+/Master
                                   BASIC 1 or 2
                                   Any OS, Any DOS
     PERIPHERALS                   None
     TAPE COMPATIBILITY            N/A
     
     
     LINENUMBER                    23470-23730
     NAME                          PROCqsort
        
     
     AUTHOR                        J. Meers
     REFERENCE                     Quicksort Routine
     
     CLASSIFICATION                Sort
     DESCRIPTION                   Sorts an array into order using the
                                   "quicksort" procedure.
     
     PARAMETERS REQUIRED      n%   length of the array.

     PARAMETERS RETURNED           none.

     GLOBAL VARIABLES              none.

     MODE DEPENDENCE               none
     
     OTHER MODULES CALLED          none.
     OTHER MODULES RELATED         none.

     DATA STRUCTURE                The items to be sorted are stored as 
                                   text strings in an array K$(n%).  A
further array p%(n%) is also used to show how related data can be managed
by the same procedure.  The key field (in this case K$) can readily be
changed to be any variable type.


     COMMENTS                      The called procedure sets up local
                                   variables so that these are not set up
recursively.  It then calls the recursive quicksort routine.  For details
of how this works refer to any textbook on computer algorithms.  Basically
it works by dividing the array in half and swapping items so that all in
the upper half are greater than the lower half.  It then repeats this
procedure with each of the halves to sort into four "piles" and so on
until it gets down to single items.  It is complicated to follow, but very
quick.  To simplify swapping additional fields along with the keyfield the
swapping of items is carried out by a separate small procedure.
                                   
     TYPICAL CALL AND LISTING

   10 REM Quicksort Routine
   20 :
   30 n%=100
   50 DIM K$(n%),p%(n%)
   60 REM Put some data in them
   70 :                                                                                                                             
   80 PROCqsort(n%)
   90 END
  100 : 
23470 REM *****************************
23480 REM *                           *
23490 REM *   Quicksort Routine       *
23500 REM *    J. Meers  1986         *
23510 REM * Prestel Mailbox 707327277 *
23520 REM *                           *
23530 REM *****************************
23540 :
23550 REM Quicksort Routine
23560 DEF PROCqsort(n%):LOCAL t$,t%,m$,rp%
23570 PROCQsort(0,n%):ENDPROC
23580 :
23590 DEF PROCQsort(l%,r%):IF r%-l%>1 THEN 23610
23600 IF K$(l%)>K$(r%) THEN PROCswap(l%,r%):ENDPROC:ELSE ENDPROC
23610 LOCAL lp%:lp%=l%-1:rp%=r%+1:m$=K$((l%+r%)DIV 2):REPEAT
23620   REPEAT:lp%=lp%+1:UNTIL K$(lp%)>=m$
23630   REPEAT:rp%=rp%-1:UNTIL K$(rp%)<=m$
23640   IF lp%<rp% THEN PROCswap(lp%,rp%)
23650   UNTIL lp%>=rp%
23660 PROCQsort(l%,rp%):PROCQsort(lp%,r%)
23670 ENDPROC
23680 :
23690 DEF PROCswap(a%,b%)
23700 t$=K$(a%):K$(a%)=K$(b%):K$(b%)=t$
23710 t%=p%(a%):p%(a%)=p%(b%):p%(b%)=t%
23720 ENDPROC
23730 :
00000000  20 20 20 20 20 44 49 53  43 20 4e 55 4d 42 45 52  |     DISC NUMBER|
00000010  20 3a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  | :              |
00000020  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000030  20 20 44 49 53 43 20 43  41 54 45 47 4f 52 59 20  |  DISC CATEGORY |
00000040  3a 20 53 4f 52 54 0d 20  20 20 20 20 20 20 20 20  |: SORT.         |
00000050  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000070  20 20 20 20 20 20 20 20  20 46 49 4c 45 4e 41 4d  |         FILENAM|
00000080  45 20 3a 20 46 2e 51 53  4f 52 54 2d 54 0d 20 20  |E : F.QSORT-T.  |
00000090  20 20 20 0d 20 20 20 20  20 0d 20 20 20 20 20 4d  |   .     .     M|
000000a0  41 43 48 49 4e 45 20 20  20 20 20 20 20 20 20 20  |ACHINE          |
000000b0  20 20 20 20 20 20 20 20  20 20 20 20 20 42 42 43  |             BBC|
000000c0  20 42 2f 42 2b 2f 4d 61  73 74 65 72 0d 20 20 20  | B/B+/Master.   |
000000d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000000f0  42 41 53 49 43 20 31 20  6f 72 20 32 0d 20 20 20  |BASIC 1 or 2.   |
00000100  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000120  41 6e 79 20 4f 53 2c 20  41 6e 79 20 44 4f 53 0d  |Any OS, Any DOS.|
00000130  20 20 20 20 20 50 45 52  49 50 48 45 52 41 4c 53  |     PERIPHERALS|
00000140  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000150  20 20 20 4e 6f 6e 65 0d  20 20 20 20 20 54 41 50  |   None.     TAP|
00000160  45 20 43 4f 4d 50 41 54  49 42 49 4c 49 54 59 20  |E COMPATIBILITY |
00000170  20 20 20 20 20 20 20 20  20 20 20 4e 2f 41 0d 20  |           N/A. |
00000180  20 20 20 20 0d 20 20 20  20 20 0d 20 20 20 20 20  |    .     .     |
00000190  4c 49 4e 45 4e 55 4d 42  45 52 20 20 20 20 20 20  |LINENUMBER      |
000001a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 32 33  |              23|
000001b0  34 37 30 2d 32 33 37 33  30 0d 20 20 20 20 20 4e  |470-23730.     N|
000001c0  41 4d 45 20 20 20 20 20  20 20 20 20 20 20 20 20  |AME             |
000001d0  20 20 20 20 20 20 20 20  20 20 20 20 20 50 52 4f  |             PRO|
000001e0  43 71 73 6f 72 74 0d 20  20 20 20 20 20 20 20 0d  |Cqsort.        .|
000001f0  20 20 20 20 20 0d 20 20  20 20 20 41 55 54 48 4f  |     .     AUTHO|
00000200  52 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |R               |
00000210  20 20 20 20 20 20 20 20  20 4a 2e 20 4d 65 65 72  |         J. Meer|
00000220  73 0d 20 20 20 20 20 52  45 46 45 52 45 4e 43 45  |s.     REFERENCE|
00000230  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000240  20 20 20 20 20 51 75 69  63 6b 73 6f 72 74 20 52  |     Quicksort R|
00000250  6f 75 74 69 6e 65 0d 20  20 20 20 20 0d 20 20 20  |outine.     .   |
00000260  20 20 43 4c 41 53 53 49  46 49 43 41 54 49 4f 4e  |  CLASSIFICATION|
00000270  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000280  53 6f 72 74 0d 20 20 20  20 20 44 45 53 43 52 49  |Sort.     DESCRI|
00000290  50 54 49 4f 4e 20 20 20  20 20 20 20 20 20 20 20  |PTION           |
000002a0  20 20 20 20 20 20 20 20  53 6f 72 74 73 20 61 6e  |        Sorts an|
000002b0  20 61 72 72 61 79 20 69  6e 74 6f 20 6f 72 64 65  | array into orde|
000002c0  72 20 75 73 69 6e 67 20  74 68 65 0d 20 20 20 20  |r using the.    |
000002d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000002e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 22  |               "|
000002f0  71 75 69 63 6b 73 6f 72  74 22 20 70 72 6f 63 65  |quicksort" proce|
00000300  64 75 72 65 2e 0d 20 20  20 20 20 0d 20 20 20 20  |dure..     .    |
00000310  20 50 41 52 41 4d 45 54  45 52 53 20 52 45 51 55  | PARAMETERS REQU|
00000320  49 52 45 44 20 20 20 20  20 20 6e 25 20 20 20 6c  |IRED      n%   l|
00000330  65 6e 67 74 68 20 6f 66  20 74 68 65 20 61 72 72  |ength of the arr|
00000340  61 79 2e 0d 0d 20 20 20  20 20 50 41 52 41 4d 45  |ay...     PARAME|
00000350  54 45 52 53 20 52 45 54  55 52 4e 45 44 20 20 20  |TERS RETURNED   |
00000360  20 20 20 20 20 20 20 20  6e 6f 6e 65 2e 0d 0d 20  |        none... |
00000370  20 20 20 20 47 4c 4f 42  41 4c 20 56 41 52 49 41  |    GLOBAL VARIA|
00000380  42 4c 45 53 20 20 20 20  20 20 20 20 20 20 20 20  |BLES            |
00000390  20 20 6e 6f 6e 65 2e 0d  0d 20 20 20 20 20 4d 4f  |  none...     MO|
000003a0  44 45 20 44 45 50 45 4e  44 45 4e 43 45 20 20 20  |DE DEPENDENCE   |
000003b0  20 20 20 20 20 20 20 20  20 20 20 20 6e 6f 6e 65  |            none|
000003c0  0d 20 20 20 20 20 0d 20  20 20 20 20 4f 54 48 45  |.     .     OTHE|
000003d0  52 20 4d 4f 44 55 4c 45  53 20 43 41 4c 4c 45 44  |R MODULES CALLED|
000003e0  20 20 20 20 20 20 20 20  20 20 6e 6f 6e 65 2e 0d  |          none..|
000003f0  20 20 20 20 20 4f 54 48  45 52 20 4d 4f 44 55 4c  |     OTHER MODUL|
00000400  45 53 20 52 45 4c 41 54  45 44 20 20 20 20 20 20  |ES RELATED      |
00000410  20 20 20 6e 6f 6e 65 2e  0d 0d 20 20 20 20 20 44  |   none...     D|
00000420  41 54 41 20 53 54 52 55  43 54 55 52 45 20 20 20  |ATA STRUCTURE   |
00000430  20 20 20 20 20 20 20 20  20 20 20 20 20 54 68 65  |             The|
00000440  20 69 74 65 6d 73 20 74  6f 20 62 65 20 73 6f 72  | items to be sor|
00000450  74 65 64 20 61 72 65 20  73 74 6f 72 65 64 20 61  |ted are stored a|
00000460  73 20 0d 20 20 20 20 20  20 20 20 20 20 20 20 20  |s .             |
00000470  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000480  20 20 20 20 20 20 74 65  78 74 20 73 74 72 69 6e  |      text strin|
00000490  67 73 20 69 6e 20 61 6e  20 61 72 72 61 79 20 4b  |gs in an array K|
000004a0  24 28 6e 25 29 2e 20 20  41 0d 66 75 72 74 68 65  |$(n%).  A.furthe|
000004b0  72 20 61 72 72 61 79 20  70 25 28 6e 25 29 20 69  |r array p%(n%) i|
000004c0  73 20 61 6c 73 6f 20 75  73 65 64 20 74 6f 20 73  |s also used to s|
000004d0  68 6f 77 20 68 6f 77 20  72 65 6c 61 74 65 64 20  |how how related |
000004e0  64 61 74 61 20 63 61 6e  20 62 65 20 6d 61 6e 61  |data can be mana|
000004f0  67 65 64 0d 62 79 20 74  68 65 20 73 61 6d 65 20  |ged.by the same |
00000500  70 72 6f 63 65 64 75 72  65 2e 20 20 54 68 65 20  |procedure.  The |
00000510  6b 65 79 20 66 69 65 6c  64 20 28 69 6e 20 74 68  |key field (in th|
00000520  69 73 20 63 61 73 65 20  4b 24 29 20 63 61 6e 20  |is case K$) can |
00000530  72 65 61 64 69 6c 79 20  62 65 0d 63 68 61 6e 67  |readily be.chang|
00000540  65 64 20 74 6f 20 62 65  20 61 6e 79 20 76 61 72  |ed to be any var|
00000550  69 61 62 6c 65 20 74 79  70 65 2e 0d 0d 0d 20 20  |iable type....  |
00000560  20 20 20 43 4f 4d 4d 45  4e 54 53 20 20 20 20 20  |   COMMENTS     |
00000570  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000580  20 54 68 65 20 63 61 6c  6c 65 64 20 70 72 6f 63  | The called proc|
00000590  65 64 75 72 65 20 73 65  74 73 20 75 70 20 6c 6f  |edure sets up lo|
000005a0  63 61 6c 0d 20 20 20 20  20 20 20 20 20 20 20 20  |cal.            |
000005b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000005c0  20 20 20 20 20 20 20 76  61 72 69 61 62 6c 65 73  |       variables|
000005d0  20 73 6f 20 74 68 61 74  20 74 68 65 73 65 20 61  | so that these a|
000005e0  72 65 20 6e 6f 74 20 73  65 74 20 75 70 0d 72 65  |re not set up.re|
000005f0  63 75 72 73 69 76 65 6c  79 2e 20 20 49 74 20 74  |cursively.  It t|
00000600  68 65 6e 20 63 61 6c 6c  73 20 74 68 65 20 72 65  |hen calls the re|
00000610  63 75 72 73 69 76 65 20  71 75 69 63 6b 73 6f 72  |cursive quicksor|
00000620  74 20 72 6f 75 74 69 6e  65 2e 20 20 46 6f 72 20  |t routine.  For |
00000630  64 65 74 61 69 6c 73 0d  6f 66 20 68 6f 77 20 74  |details.of how t|
00000640  68 69 73 20 77 6f 72 6b  73 20 72 65 66 65 72 20  |his works refer |
00000650  74 6f 20 61 6e 79 20 74  65 78 74 62 6f 6f 6b 20  |to any textbook |
00000660  6f 6e 20 63 6f 6d 70 75  74 65 72 20 61 6c 67 6f  |on computer algo|
00000670  72 69 74 68 6d 73 2e 20  20 42 61 73 69 63 61 6c  |rithms.  Basical|
00000680  6c 79 0d 69 74 20 77 6f  72 6b 73 20 62 79 20 64  |ly.it works by d|
00000690  69 76 69 64 69 6e 67 20  74 68 65 20 61 72 72 61  |ividing the arra|
000006a0  79 20 69 6e 20 68 61 6c  66 20 61 6e 64 20 73 77  |y in half and sw|
000006b0  61 70 70 69 6e 67 20 69  74 65 6d 73 20 73 6f 20  |apping items so |
000006c0  74 68 61 74 20 61 6c 6c  20 69 6e 0d 74 68 65 20  |that all in.the |
000006d0  75 70 70 65 72 20 68 61  6c 66 20 61 72 65 20 67  |upper half are g|
000006e0  72 65 61 74 65 72 20 74  68 61 6e 20 74 68 65 20  |reater than the |
000006f0  6c 6f 77 65 72 20 68 61  6c 66 2e 20 20 49 74 20  |lower half.  It |
00000700  74 68 65 6e 20 72 65 70  65 61 74 73 20 74 68 69  |then repeats thi|
00000710  73 0d 70 72 6f 63 65 64  75 72 65 20 77 69 74 68  |s.procedure with|
00000720  20 65 61 63 68 20 6f 66  20 74 68 65 20 68 61 6c  | each of the hal|
00000730  76 65 73 20 74 6f 20 73  6f 72 74 20 69 6e 74 6f  |ves to sort into|
00000740  20 66 6f 75 72 20 22 70  69 6c 65 73 22 20 61 6e  | four "piles" an|
00000750  64 20 73 6f 20 6f 6e 0d  75 6e 74 69 6c 20 69 74  |d so on.until it|
00000760  20 67 65 74 73 20 64 6f  77 6e 20 74 6f 20 73 69  | gets down to si|
00000770  6e 67 6c 65 20 69 74 65  6d 73 2e 20 20 49 74 20  |ngle items.  It |
00000780  69 73 20 63 6f 6d 70 6c  69 63 61 74 65 64 20 74  |is complicated t|
00000790  6f 20 66 6f 6c 6c 6f 77  2c 20 62 75 74 20 76 65  |o follow, but ve|
000007a0  72 79 0d 71 75 69 63 6b  2e 20 20 54 6f 20 73 69  |ry.quick.  To si|
000007b0  6d 70 6c 69 66 79 20 73  77 61 70 70 69 6e 67 20  |mplify swapping |
000007c0  61 64 64 69 74 69 6f 6e  61 6c 20 66 69 65 6c 64  |additional field|
000007d0  73 20 61 6c 6f 6e 67 20  77 69 74 68 20 74 68 65  |s along with the|
000007e0  20 6b 65 79 66 69 65 6c  64 20 74 68 65 0d 73 77  | keyfield the.sw|
000007f0  61 70 70 69 6e 67 20 6f  66 20 69 74 65 6d 73 20  |apping of items |
00000800  69 73 20 63 61 72 72 69  65 64 20 6f 75 74 20 62  |is carried out b|
00000810  79 20 61 20 73 65 70 61  72 61 74 65 20 73 6d 61  |y a separate sma|
00000820  6c 6c 20 70 72 6f 63 65  64 75 72 65 2e 0d 20 20  |ll procedure..  |
00000830  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000850  20 0d 20 20 20 20 20 54  59 50 49 43 41 4c 20 43  | .     TYPICAL C|
00000860  41 4c 4c 20 41 4e 44 20  4c 49 53 54 49 4e 47 0d  |ALL AND LISTING.|
00000870  0d 20 20 20 31 30 20 52  45 4d 20 51 75 69 63 6b  |.   10 REM Quick|
00000880  73 6f 72 74 20 52 6f 75  74 69 6e 65 0d 20 20 20  |sort Routine.   |
00000890  32 30 20 3a 0d 20 20 20  33 30 20 6e 25 3d 31 30  |20 :.   30 n%=10|
000008a0  30 0d 20 20 20 35 30 20  44 49 4d 20 4b 24 28 6e  |0.   50 DIM K$(n|
000008b0  25 29 2c 70 25 28 6e 25  29 0d 20 20 20 36 30 20  |%),p%(n%).   60 |
000008c0  52 45 4d 20 50 75 74 20  73 6f 6d 65 20 64 61 74  |REM Put some dat|
000008d0  61 20 69 6e 20 74 68 65  6d 0d 20 20 20 37 30 20  |a in them.   70 |
000008e0  3a 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |:               |
000008f0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000950  20 20 20 20 20 20 20 20  20 20 20 20 20 20 0d 20  |              . |
00000960  20 20 38 30 20 50 52 4f  43 71 73 6f 72 74 28 6e  |  80 PROCqsort(n|
00000970  25 29 0d 20 20 20 39 30  20 45 4e 44 0d 20 20 31  |%).   90 END.  1|
00000980  30 30 20 3a 20 0d 32 33  34 37 30 20 52 45 4d 20  |00 : .23470 REM |
00000990  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
000009a0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 0d 32 33  |*************.23|
000009b0  34 38 30 20 52 45 4d 20  2a 20 20 20 20 20 20 20  |480 REM *       |
000009c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000009d0  20 20 20 20 2a 0d 32 33  34 39 30 20 52 45 4d 20  |    *.23490 REM |
000009e0  2a 20 20 20 51 75 69 63  6b 73 6f 72 74 20 52 6f  |*   Quicksort Ro|
000009f0  75 74 69 6e 65 20 20 20  20 20 20 20 2a 0d 32 33  |utine       *.23|
00000a00  35 30 30 20 52 45 4d 20  2a 20 20 20 20 4a 2e 20  |500 REM *    J. |
00000a10  4d 65 65 72 73 20 20 31  39 38 36 20 20 20 20 20  |Meers  1986     |
00000a20  20 20 20 20 2a 0d 32 33  35 31 30 20 52 45 4d 20  |    *.23510 REM |
00000a30  2a 20 50 72 65 73 74 65  6c 20 4d 61 69 6c 62 6f  |* Prestel Mailbo|
00000a40  78 20 37 30 37 33 32 37  32 37 37 20 2a 0d 32 33  |x 707327277 *.23|
00000a50  35 32 30 20 52 45 4d 20  2a 20 20 20 20 20 20 20  |520 REM *       |
00000a60  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000a70  20 20 20 20 2a 0d 32 33  35 33 30 20 52 45 4d 20  |    *.23530 REM |
00000a80  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
00000a90  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 0d 32 33  |*************.23|
00000aa0  35 34 30 20 3a 0d 32 33  35 35 30 20 52 45 4d 20  |540 :.23550 REM |
00000ab0  51 75 69 63 6b 73 6f 72  74 20 52 6f 75 74 69 6e  |Quicksort Routin|
00000ac0  65 0d 32 33 35 36 30 20  44 45 46 20 50 52 4f 43  |e.23560 DEF PROC|
00000ad0  71 73 6f 72 74 28 6e 25  29 3a 4c 4f 43 41 4c 20  |qsort(n%):LOCAL |
00000ae0  74 24 2c 74 25 2c 6d 24  2c 72 70 25 0d 32 33 35  |t$,t%,m$,rp%.235|
00000af0  37 30 20 50 52 4f 43 51  73 6f 72 74 28 30 2c 6e  |70 PROCQsort(0,n|
00000b00  25 29 3a 45 4e 44 50 52  4f 43 0d 32 33 35 38 30  |%):ENDPROC.23580|
00000b10  20 3a 0d 32 33 35 39 30  20 44 45 46 20 50 52 4f  | :.23590 DEF PRO|
00000b20  43 51 73 6f 72 74 28 6c  25 2c 72 25 29 3a 49 46  |CQsort(l%,r%):IF|
00000b30  20 72 25 2d 6c 25 3e 31  20 54 48 45 4e 20 32 33  | r%-l%>1 THEN 23|
00000b40  36 31 30 0d 32 33 36 30  30 20 49 46 20 4b 24 28  |610.23600 IF K$(|
00000b50  6c 25 29 3e 4b 24 28 72  25 29 20 54 48 45 4e 20  |l%)>K$(r%) THEN |
00000b60  50 52 4f 43 73 77 61 70  28 6c 25 2c 72 25 29 3a  |PROCswap(l%,r%):|
00000b70  45 4e 44 50 52 4f 43 3a  45 4c 53 45 20 45 4e 44  |ENDPROC:ELSE END|
00000b80  50 52 4f 43 0d 32 33 36  31 30 20 4c 4f 43 41 4c  |PROC.23610 LOCAL|
00000b90  20 6c 70 25 3a 6c 70 25  3d 6c 25 2d 31 3a 72 70  | lp%:lp%=l%-1:rp|
00000ba0  25 3d 72 25 2b 31 3a 6d  24 3d 4b 24 28 28 6c 25  |%=r%+1:m$=K$((l%|
00000bb0  2b 72 25 29 44 49 56 20  32 29 3a 52 45 50 45 41  |+r%)DIV 2):REPEA|
00000bc0  54 0d 32 33 36 32 30 20  20 20 52 45 50 45 41 54  |T.23620   REPEAT|
00000bd0  3a 6c 70 25 3d 6c 70 25  2b 31 3a 55 4e 54 49 4c  |:lp%=lp%+1:UNTIL|
00000be0  20 4b 24 28 6c 70 25 29  3e 3d 6d 24 0d 32 33 36  | K$(lp%)>=m$.236|
00000bf0  33 30 20 20 20 52 45 50  45 41 54 3a 72 70 25 3d  |30   REPEAT:rp%=|
00000c00  72 70 25 2d 31 3a 55 4e  54 49 4c 20 4b 24 28 72  |rp%-1:UNTIL K$(r|
00000c10  70 25 29 3c 3d 6d 24 0d  32 33 36 34 30 20 20 20  |p%)<=m$.23640   |
00000c20  49 46 20 6c 70 25 3c 72  70 25 20 54 48 45 4e 20  |IF lp%<rp% THEN |
00000c30  50 52 4f 43 73 77 61 70  28 6c 70 25 2c 72 70 25  |PROCswap(lp%,rp%|
00000c40  29 0d 32 33 36 35 30 20  20 20 55 4e 54 49 4c 20  |).23650   UNTIL |
00000c50  6c 70 25 3e 3d 72 70 25  0d 32 33 36 36 30 20 50  |lp%>=rp%.23660 P|
00000c60  52 4f 43 51 73 6f 72 74  28 6c 25 2c 72 70 25 29  |ROCQsort(l%,rp%)|
00000c70  3a 50 52 4f 43 51 73 6f  72 74 28 6c 70 25 2c 72  |:PROCQsort(lp%,r|
00000c80  25 29 0d 32 33 36 37 30  20 45 4e 44 50 52 4f 43  |%).23670 ENDPROC|
00000c90  0d 32 33 36 38 30 20 3a  0d 32 33 36 39 30 20 44  |.23680 :.23690 D|
00000ca0  45 46 20 50 52 4f 43 73  77 61 70 28 61 25 2c 62  |EF PROCswap(a%,b|
00000cb0  25 29 0d 32 33 37 30 30  20 74 24 3d 4b 24 28 61  |%).23700 t$=K$(a|
00000cc0  25 29 3a 4b 24 28 61 25  29 3d 4b 24 28 62 25 29  |%):K$(a%)=K$(b%)|
00000cd0  3a 4b 24 28 62 25 29 3d  74 24 0d 32 33 37 31 30  |:K$(b%)=t$.23710|
00000ce0  20 74 25 3d 70 25 28 61  25 29 3a 70 25 28 61 25  | t%=p%(a%):p%(a%|
00000cf0  29 3d 70 25 28 62 25 29  3a 70 25 28 62 25 29 3d  |)=p%(b%):p%(b%)=|
00000d00  74 25 0d 32 33 37 32 30  20 45 4e 44 50 52 4f 43  |t%.23720 ENDPROC|
00000d10  0d 32 33 37 33 30 20 3a  0d                       |.23730 :.|
00000d19
General/FQSORTT.m0
General/FQSORTT.m1
General/FQSORTT.m2
General/FQSORTT.m4
General/FQSORTT.m5