Home » CEEFAX disks » telesoftware16.adl » 18-06-89/QSDemo

18-06-89/QSDemo

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 » telesoftware16.adl
Filename: 18-06-89/QSDemo
Read OK:
File size: 0FEA bytes
Load address: FFFF0E00
Exec address: FFFF802B
File contents
   10 REM     Demonstration of Quicksort
   20 REM     Ian Rickards, January 1989
   30 
   40 MODE 7
   50 ON ERROR GOTO 220
   60 PROCinstructions
   70 PROCsetup
   80 PROCwait
   90 CLS
  100 PROCcentre( "Demonstration of Quicksort" )
  110 PROCcentre( "_____________ __ _________" )
  120 PRINT CHR$ &87 CHR$ &FF " Super-pointer"
  130 PRINT CHR$ &82 CHR$ &FF " Moveable pointer"
  140 ?at = VPOS
  150 REPEAT
  160 PROCshuffle
  170 FOR loop = 1 TO no
  180 PRINT TAB( 1, loop + ?at ) swap$( at?loop );
  190 NEXT
  200 PROCsort( "entire ", 1, 1, no )
  210 UNTIL FNexit
  220 MODE 7
  230 END
  240 
  250 DEF PROCsetup
  260 hi = 19
  270 no = hi + 1
  280 max = 9
  290 DIM word$( hi ), swap$( hi ), at no, read max, pos 1, add%( 1 )
  300 start = at + 1
  310 FOR loop = 0 TO hi
  320 start?loop = loop
  330 READ $read
  340 word$( loop ) = $read
  350 swap$( loop ) = $read + STRING$( max - LEN $read, " " )
  360 NEXT
  370 add%( 0 ) = +1
  380 add%( 1 ) = -1
  390 ENDPROC
  400 
  410 DEF PROCshuffle
  420 FOR loop = no TO 2 STEP -1
  430 pick = RND( loop )
  440 PROCswap( loop, pick )
  450 NEXT
  460 ENDPROC
  470 
  480 DEF PROCsort( side$, depth, first, last )
  490 IF first = last PROCeasy
  500 IF first < last PROCquick
  510 ENDPROC
  520 
  530 DEF PROCquick
  540 PROCmessage( "Quicksort " + side$ + "list" )
  550 FOR loop = first TO last
  560 PROCcolour( loop, 6 )
  570 NEXT
  580 PROCwait
  590 PROCwipe
  600 FOR loop = first TO last
  610 PROCcolour( loop, 1 )
  620 NEXT
  630 PROCright
  640 LOCAL mid
  650 mid = FNheap
  660 PROCsort( "upper sub-", depth + 1, first, mid - 1 )
  670 PROCsort( "lower sub-", depth + 1, mid + 1, last )
  680 PROCwait
  690 PROCleft
  700 ENDPROC
  710 
  720 DEF FNheap
  730 pos?0 = first
  740 pos?1 = last
  750 move = 1
  760 PROCcolour( pos?0, 8 )
  770 REPEAT
  780 PROCcolour( pos?move, 2 )
  790 IF at?pos?0 > at?pos?1 PROCexchange
  800 PROCwait
  810 PROCcolour( pos?move, 1 )
  820 pos?move = pos?move + add%( move )
  830 UNTIL pos?0 = pos?1
  840 PROCmessage( "In final position" )
  850 PROCcolour( ?pos, 3 )
  860 PROCwait
  870 PROCwipe
  880 = ?pos
  890 
  900 DEF PROCexchange
  910 PROCmessage( "Swap" )
  920 PROCwait
  930 PROCwipe
  940 PROCswap( pos?0, pos?1 )
  950 PROCcolour( pos?move, 8 )
  960 move = move EOR 1
  970 PROCcolour( pos?move, 2 )
  980 PRINT TAB( depth + 1, pos?0 + ?at ) swap$( at?pos?0 );
  990 PRINT TAB( depth + 1, pos?1 + ?at ) swap$( at?pos?1 );
 1000 ENDPROC
 1010 
 1020 DEF PROCswap( i, j )
 1030 keep = at?i
 1040 at?i = at?j
 1050 at?j = keep
 1060 ENDPROC
 1070 
 1080 DEF PROCeasy
 1090 PROCcolour( last, 6 )
 1100 PROCmessage( "Easy " + side$ + "list" )
 1110 PROCwait
 1120 PROCcolour( last, 3 )
 1130 PROCwipe
 1140 ENDPROC
 1150 
 1160 DEF PROCcentre( title$ )
 1170 gap = 19 - LEN title$ DIV 2
 1180 PRINT CHR$ &83 SPC gap title$
 1190 ENDPROC
 1200 
 1210 DEF PROCright
 1220 FOR loop = first TO last
 1230 PRINT TAB( depth, loop + ?at ) " " word$( at?loop );
 1240 NEXT
 1250 ENDPROC
 1260 
 1270 DEF PROCleft
 1280 FOR loop = first TO last
 1290 PRINT TAB( depth, loop + ?at ) word$( at?loop ) " ";
 1300 NEXT
 1310 ENDPROC
 1320 
 1330 DEF PROCcolour( pos, col )
 1340 VDU 31, 0, pos + ?at, col OR &80
 1350 ENDPROC
 1360 
 1370 DEF PROCwait
 1380 dummy = GET
 1400 ENDPROC
 1410 
 1420 DEF PROCmessage( info$ )
 1430 len = LEN info$
 1440 PRINT TAB( 40 - len, 4 ) info$
 1450 ENDPROC
 1460 
 1470 DEF PROCwipe
 1480 PRINT TAB( 40 - len, 4 ) STRING$( len, " " )
 1490 ENDPROC
 1500 
 1510 DEF FNexit
 1520 PROCmessage( "Again?" )
 1530 REPEAT
 1540 key = INSTR( "YyNn", GET$ )
 1550 UNTIL key > 0
 1560 PROCwipe
 1570 = key > 2
 1580 
 1590 DEF PROCinstructions
 1600 VDU 23; &200A; 0; 0; 0;
 1610 PROCcentre( "Information" )
 1620 PROCcentre( "___________" )
 1630 PRINT
 1640 PRINT "The quicksort is a performance sort."
 1650 PRINT
 1660 PRINT "It is a natural way to sort. If you have";
 1670 PRINT "a pile of cards which need sorting, you"
 1680 PRINT "toss the cards into two new piles, one"
 1690 PRINT "for A-M and the other for N-Z. Each pile";
 1700 PRINT "is further sub-divided in the same way."
 1710 PRINT
 1720 PRINT "It is quicker and simpler to sort small"
 1730 PRINT "piles, so this is a successful policy."
 1740 PRINT
 1750 PRINT "The computer algorithm uses some clever"
 1760 PRINT "manipulations to execute quickly, but it";
 1770 PRINT "still uses the same basic idea."
 1780 PRINT
 1790 PRINT "In the demonstration, it is important to";
 1800 PRINT "notice that the list is separated into"
 1810 PRINT "lower & higher sub-lists where the"
 1820 PRINT "pointers converge."
 1830 PRINT
 1840 PROCcentre( "Press a key to step through demo" )
 1850 ENDPROC
 1860 
 1870 REM     Ordered list
 1880 
 1890 DATA Algorithm
 1900 DATA Bootstrap
 1910 DATA Converter
 1920 DATA Directory
 1930 DATA Exchange
 1940 DATA Flowchart
 1950 DATA Graphics
 1960 DATA Hardware
 1970 DATA Interface
 1980 DATA Joystick
 1990 DATA Keyboard
 2000 DATA Language
 2010 DATA Mnemonics
 2020 DATA Negative
 2030 DATA Operation
 2040 DATA Positive
 2050 DATA Quicksort
 2060 DATA Recursion
 2070 DATA Software
 2080 DATA Teletext

% �     Demonstration of Quicksort
% �     Ian Rickards, January 1989
 
( � 7
2 � � � �d\@
< �instructions
F �setup
P
 �wait
Z �
d, �centre( "Demonstration of Quicksort" )
n, �centre( "_____________ __ _________" )
x# � � &87 � &FF " Super-pointer"
�& � � &82 � &FF " Moveable pointer"
� ?at = �
� �
�
 �shuffle
� � loop = 1 � no
�* � � 1, loop + ?at ) swap$( at?loop );
� �
�! �sort( "entire ", 1, 1, no )
� � �exit
� � 7
� �
� 
�
 � �setup
 hi = 19
 no = hi + 1
 max = 9
"B � word$( hi ), swap$( hi ), at no, read max, pos 1, add%( 1 )
, start = at + 1
6 � loop = 0 � hi
@ start?loop = loop
J � $read
T word$( loop ) = $read
^3 swap$( loop ) = $read + � max - � $read, " " )
h �
r add%( 0 ) = +1
| add%( 1 ) = -1
� �
� 
� � �shuffle
� � loop = no � 2 � -1
� pick = �( loop )
� �swap( loop, pick )
� �
� �
� 
�) � �sort( side$, depth, first, last )
� � first = last �easy
� � first < last �quick
� �
 

 � �quick
. �message( "Quicksort " + side$ + "list" )
& � loop = first � last
0 �colour( loop, 6 )
: �
D
 �wait
N
 �wipe
X � loop = first � last
b �colour( loop, 1 )
l �
v �right
�
 � mid
� mid = �heap
�5 �sort( "upper sub-", depth + 1, first, mid - 1 )
�4 �sort( "lower sub-", depth + 1, mid + 1, last )
�
 �wait
�
 �left
� �
� 
� � �heap
� pos?0 = first
� pos?1 = last
�
 move = 1
� �colour( pos?0, 8 )
 �
 �colour( pos?move, 2 )
$ � at?pos?0 > at?pos?1 �exchange
 
 �wait
* �colour( pos?move, 1 )
4' pos?move = pos?move + add%( move )
> � pos?0 = pos?1
H$ �message( "In final position" )
R �colour( ?pos, 3 )
\
 �wait
f
 �wipe
p = ?pos
z 
� � �exchange
� �message( "Swap" )
�
 �wait
�
 �wipe
� �swap( pos?0, pos?1 )
� �colour( pos?move, 8 )
� move = move � 1
� �colour( pos?move, 2 )
�4 � � depth + 1, pos?0 + ?at ) swap$( at?pos?0 );
�4 � � depth + 1, pos?1 + ?at ) swap$( at?pos?1 );
� �
� 
� � �swap( i, j )
 keep = at?i
 at?i = at?j
 at?j = keep
$ �
. 
8 � �easy
B �colour( last, 6 )
L) �message( "Easy " + side$ + "list" )
V
 �wait
` �colour( last, 3 )
j
 �wipe
t �
~ 
� � �centre( title$ )
� gap = 19 - � title$ � 2
� � � &83 � gap title$
� �
� 
�
 � �right
� � loop = first � last
�2 � � depth, loop + ?at ) " " word$( at?loop );
� �
� �
� 
� � �left
 � loop = first � last

2 � � depth, loop + ?at ) word$( at?loop ) " ";
 �
 �
( 
2 � �colour( pos, col )
<" � 31, 0, pos + ?at, col � &80
F �
P 
Z � �wait
d dummy = �
x �
� 
� � �message( info$ )
� len = � info$
� � � 40 - len, 4 ) info$
� �
� 
� � �wipe
�# � � 40 - len, 4 ) � len, " " )
� �
� 
� � �exit
� �message( "Again?" )
� �
 key = � "YyNn", � )
 � key > 0

 �wipe
" = key > 2
, 
6 � �instructions
@ � 23; &200A; 0; 0; 0;
J �centre( "Information" )
T �centre( "___________" )
^ �
h- � "The quicksort is a performance sort."
r �
|2 � "It is a natural way to sort. If you have";
�0 � "a pile of cards which need sorting, you"
�/ � "toss the cards into two new piles, one"
�2 � "for A-M and the other for N-Z. Each pile";
�0 � "is further sub-divided in the same way."
� �
�0 � "It is quicker and simpler to sort small"
�/ � "piles, so this is a successful policy."
� �
�0 � "The computer algorithm uses some clever"
�2 � "manipulations to execute quickly, but it";
�( � "still uses the same basic idea."
� �
�2 � "In the demonstration, it is important to";
/ � "notice that the list is separated into"
+ � "lower & higher sub-lists where the"
 � "pointers converge."
& �
02 �centre( "Press a key to step through demo" )
: �
D 
N �     Ordered list
X 
b � Algorithm
l � Bootstrap
v � Converter
� � Directory
� � Exchange
� � Flowchart
� � Graphics
� � Hardware
� � Interface
� � Joystick
� � Keyboard
� � Language
� � Mnemonics
� � Negative
� � Operation
� � Positive
 � Quicksort
 � Recursion
 � Software
  � Teletext
�
00000000  0d 00 0a 25 20 f4 20 20  20 20 20 44 65 6d 6f 6e  |...% .     Demon|
00000010  73 74 72 61 74 69 6f 6e  20 6f 66 20 51 75 69 63  |stration of Quic|
00000020  6b 73 6f 72 74 0d 00 14  25 20 f4 20 20 20 20 20  |ksort...% .     |
00000030  49 61 6e 20 52 69 63 6b  61 72 64 73 2c 20 4a 61  |Ian Rickards, Ja|
00000040  6e 75 61 72 79 20 31 39  38 39 0d 00 1e 05 20 0d  |nuary 1989.... .|
00000050  00 28 08 20 eb 20 37 0d  00 32 0f 20 ee 20 85 20  |.(. . 7..2. . . |
00000060  e5 20 8d 64 5c 40 0d 00  3c 12 20 f2 69 6e 73 74  |. .d\@..<. .inst|
00000070  72 75 63 74 69 6f 6e 73  0d 00 46 0b 20 f2 73 65  |ructions..F. .se|
00000080  74 75 70 0d 00 50 0a 20  f2 77 61 69 74 0d 00 5a  |tup..P. .wait..Z|
00000090  06 20 db 0d 00 64 2c 20  f2 63 65 6e 74 72 65 28  |. ...d, .centre(|
000000a0  20 22 44 65 6d 6f 6e 73  74 72 61 74 69 6f 6e 20  | "Demonstration |
000000b0  6f 66 20 51 75 69 63 6b  73 6f 72 74 22 20 29 0d  |of Quicksort" ).|
000000c0  00 6e 2c 20 f2 63 65 6e  74 72 65 28 20 22 5f 5f  |.n, .centre( "__|
000000d0  5f 5f 5f 5f 5f 5f 5f 5f  5f 5f 5f 20 5f 5f 20 5f  |___________ __ _|
000000e0  5f 5f 5f 5f 5f 5f 5f 5f  22 20 29 0d 00 78 23 20  |________" )..x# |
000000f0  f1 20 bd 20 26 38 37 20  bd 20 26 46 46 20 22 20  |. . &87 . &FF " |
00000100  53 75 70 65 72 2d 70 6f  69 6e 74 65 72 22 0d 00  |Super-pointer"..|
00000110  82 26 20 f1 20 bd 20 26  38 32 20 bd 20 26 46 46  |.& . . &82 . &FF|
00000120  20 22 20 4d 6f 76 65 61  62 6c 65 20 70 6f 69 6e  | " Moveable poin|
00000130  74 65 72 22 0d 00 8c 0c  20 3f 61 74 20 3d 20 bc  |ter".... ?at = .|
00000140  0d 00 96 06 20 f5 0d 00  a0 0d 20 f2 73 68 75 66  |.... ..... .shuf|
00000150  66 6c 65 0d 00 aa 14 20  e3 20 6c 6f 6f 70 20 3d  |fle.... . loop =|
00000160  20 31 20 b8 20 6e 6f 0d  00 b4 2a 20 f1 20 8a 20  | 1 . no...* . . |
00000170  31 2c 20 6c 6f 6f 70 20  2b 20 3f 61 74 20 29 20  |1, loop + ?at ) |
00000180  73 77 61 70 24 28 20 61  74 3f 6c 6f 6f 70 20 29  |swap$( at?loop )|
00000190  3b 0d 00 be 06 20 ed 0d  00 c8 21 20 f2 73 6f 72  |;.... ....! .sor|
000001a0  74 28 20 22 65 6e 74 69  72 65 20 22 2c 20 31 2c  |t( "entire ", 1,|
000001b0  20 31 2c 20 6e 6f 20 29  0d 00 d2 0c 20 fd 20 a4  | 1, no ).... . .|
000001c0  65 78 69 74 0d 00 dc 08  20 eb 20 37 0d 00 e6 06  |exit.... . 7....|
000001d0  20 e0 0d 00 f0 05 20 0d  00 fa 0d 20 dd 20 f2 73  | ..... .... . .s|
000001e0  65 74 75 70 0d 01 04 0c  20 68 69 20 3d 20 31 39  |etup.... hi = 19|
000001f0  0d 01 0e 10 20 6e 6f 20  3d 20 68 69 20 2b 20 31  |.... no = hi + 1|
00000200  0d 01 18 0c 20 6d 61 78  20 3d 20 39 0d 01 22 42  |.... max = 9.."B|
00000210  20 de 20 77 6f 72 64 24  28 20 68 69 20 29 2c 20  | . word$( hi ), |
00000220  73 77 61 70 24 28 20 68  69 20 29 2c 20 61 74 20  |swap$( hi ), at |
00000230  6e 6f 2c 20 72 65 61 64  20 6d 61 78 2c 20 70 6f  |no, read max, po|
00000240  73 20 31 2c 20 61 64 64  25 28 20 31 20 29 0d 01  |s 1, add%( 1 )..|
00000250  2c 13 20 73 74 61 72 74  20 3d 20 61 74 20 2b 20  |,. start = at + |
00000260  31 0d 01 36 14 20 e3 20  6c 6f 6f 70 20 3d 20 30  |1..6. . loop = 0|
00000270  20 b8 20 68 69 0d 01 40  16 20 73 74 61 72 74 3f  | . hi..@. start?|
00000280  6c 6f 6f 70 20 3d 20 6c  6f 6f 70 0d 01 4a 0c 20  |loop = loop..J. |
00000290  f3 20 24 72 65 61 64 0d  01 54 1a 20 77 6f 72 64  |. $read..T. word|
000002a0  24 28 20 6c 6f 6f 70 20  29 20 3d 20 24 72 65 61  |$( loop ) = $rea|
000002b0  64 0d 01 5e 33 20 73 77  61 70 24 28 20 6c 6f 6f  |d..^3 swap$( loo|
000002c0  70 20 29 20 3d 20 24 72  65 61 64 20 2b 20 c4 20  |p ) = $read + . |
000002d0  6d 61 78 20 2d 20 a9 20  24 72 65 61 64 2c 20 22  |max - . $read, "|
000002e0  20 22 20 29 0d 01 68 06  20 ed 0d 01 72 13 20 61  | " )..h. ...r. a|
000002f0  64 64 25 28 20 30 20 29  20 3d 20 2b 31 0d 01 7c  |dd%( 0 ) = +1..||
00000300  13 20 61 64 64 25 28 20  31 20 29 20 3d 20 2d 31  |. add%( 1 ) = -1|
00000310  0d 01 86 06 20 e1 0d 01  90 05 20 0d 01 9a 0f 20  |.... ..... .... |
00000320  dd 20 f2 73 68 75 66 66  6c 65 0d 01 a4 19 20 e3  |. .shuffle.... .|
00000330  20 6c 6f 6f 70 20 3d 20  6e 6f 20 b8 20 32 20 88  | loop = no . 2 .|
00000340  20 2d 31 0d 01 ae 15 20  70 69 63 6b 20 3d 20 b3  | -1.... pick = .|
00000350  28 20 6c 6f 6f 70 20 29  0d 01 b8 18 20 f2 73 77  |( loop ).... .sw|
00000360  61 70 28 20 6c 6f 6f 70  2c 20 70 69 63 6b 20 29  |ap( loop, pick )|
00000370  0d 01 c2 06 20 ed 0d 01  cc 06 20 e1 0d 01 d6 05  |.... ..... .....|
00000380  20 0d 01 e0 29 20 dd 20  f2 73 6f 72 74 28 20 73  | ...) . .sort( s|
00000390  69 64 65 24 2c 20 64 65  70 74 68 2c 20 66 69 72  |ide$, depth, fir|
000003a0  73 74 2c 20 6c 61 73 74  20 29 0d 01 ea 19 20 e7  |st, last ).... .|
000003b0  20 66 69 72 73 74 20 3d  20 6c 61 73 74 20 f2 65  | first = last .e|
000003c0  61 73 79 0d 01 f4 1a 20  e7 20 66 69 72 73 74 20  |asy.... . first |
000003d0  3c 20 6c 61 73 74 20 f2  71 75 69 63 6b 0d 01 fe  |< last .quick...|
000003e0  06 20 e1 0d 02 08 05 20  0d 02 12 0d 20 dd 20 f2  |. ..... .... . .|
000003f0  71 75 69 63 6b 0d 02 1c  2e 20 f2 6d 65 73 73 61  |quick.... .messa|
00000400  67 65 28 20 22 51 75 69  63 6b 73 6f 72 74 20 22  |ge( "Quicksort "|
00000410  20 2b 20 73 69 64 65 24  20 2b 20 22 6c 69 73 74  | + side$ + "list|
00000420  22 20 29 0d 02 26 1a 20  e3 20 6c 6f 6f 70 20 3d  |" )..&. . loop =|
00000430  20 66 69 72 73 74 20 b8  20 6c 61 73 74 0d 02 30  | first . last..0|
00000440  17 20 f2 63 6f 6c 6f 75  72 28 20 6c 6f 6f 70 2c  |. .colour( loop,|
00000450  20 36 20 29 0d 02 3a 06  20 ed 0d 02 44 0a 20 f2  | 6 )..:. ...D. .|
00000460  77 61 69 74 0d 02 4e 0a  20 f2 77 69 70 65 0d 02  |wait..N. .wipe..|
00000470  58 1a 20 e3 20 6c 6f 6f  70 20 3d 20 66 69 72 73  |X. . loop = firs|
00000480  74 20 b8 20 6c 61 73 74  0d 02 62 17 20 f2 63 6f  |t . last..b. .co|
00000490  6c 6f 75 72 28 20 6c 6f  6f 70 2c 20 31 20 29 0d  |lour( loop, 1 ).|
000004a0  02 6c 06 20 ed 0d 02 76  0b 20 f2 72 69 67 68 74  |.l. ...v. .right|
000004b0  0d 02 80 0a 20 ea 20 6d  69 64 0d 02 8a 10 20 6d  |.... . mid.... m|
000004c0  69 64 20 3d 20 a4 68 65  61 70 0d 02 94 35 20 f2  |id = .heap...5 .|
000004d0  73 6f 72 74 28 20 22 75  70 70 65 72 20 73 75 62  |sort( "upper sub|
000004e0  2d 22 2c 20 64 65 70 74  68 20 2b 20 31 2c 20 66  |-", depth + 1, f|
000004f0  69 72 73 74 2c 20 6d 69  64 20 2d 20 31 20 29 0d  |irst, mid - 1 ).|
00000500  02 9e 34 20 f2 73 6f 72  74 28 20 22 6c 6f 77 65  |..4 .sort( "lowe|
00000510  72 20 73 75 62 2d 22 2c  20 64 65 70 74 68 20 2b  |r sub-", depth +|
00000520  20 31 2c 20 6d 69 64 20  2b 20 31 2c 20 6c 61 73  | 1, mid + 1, las|
00000530  74 20 29 0d 02 a8 0a 20  f2 77 61 69 74 0d 02 b2  |t ).... .wait...|
00000540  0a 20 f2 6c 65 66 74 0d  02 bc 06 20 e1 0d 02 c6  |. .left.... ....|
00000550  05 20 0d 02 d0 0c 20 dd  20 a4 68 65 61 70 0d 02  |. .... . .heap..|
00000560  da 12 20 70 6f 73 3f 30  20 3d 20 66 69 72 73 74  |.. pos?0 = first|
00000570  0d 02 e4 11 20 70 6f 73  3f 31 20 3d 20 6c 61 73  |.... pos?1 = las|
00000580  74 0d 02 ee 0d 20 6d 6f  76 65 20 3d 20 31 0d 02  |t.... move = 1..|
00000590  f8 18 20 f2 63 6f 6c 6f  75 72 28 20 70 6f 73 3f  |.. .colour( pos?|
000005a0  30 2c 20 38 20 29 0d 03  02 06 20 f5 0d 03 0c 1b  |0, 8 ).... .....|
000005b0  20 f2 63 6f 6c 6f 75 72  28 20 70 6f 73 3f 6d 6f  | .colour( pos?mo|
000005c0  76 65 2c 20 32 20 29 0d  03 16 24 20 e7 20 61 74  |ve, 2 )...$ . at|
000005d0  3f 70 6f 73 3f 30 20 3e  20 61 74 3f 70 6f 73 3f  |?pos?0 > at?pos?|
000005e0  31 20 f2 65 78 63 68 61  6e 67 65 0d 03 20 0a 20  |1 .exchange.. . |
000005f0  f2 77 61 69 74 0d 03 2a  1b 20 f2 63 6f 6c 6f 75  |.wait..*. .colou|
00000600  72 28 20 70 6f 73 3f 6d  6f 76 65 2c 20 31 20 29  |r( pos?move, 1 )|
00000610  0d 03 34 27 20 70 6f 73  3f 6d 6f 76 65 20 3d 20  |..4' pos?move = |
00000620  70 6f 73 3f 6d 6f 76 65  20 2b 20 61 64 64 25 28  |pos?move + add%(|
00000630  20 6d 6f 76 65 20 29 0d  03 3e 14 20 fd 20 70 6f  | move )..>. . po|
00000640  73 3f 30 20 3d 20 70 6f  73 3f 31 0d 03 48 24 20  |s?0 = pos?1..H$ |
00000650  f2 6d 65 73 73 61 67 65  28 20 22 49 6e 20 66 69  |.message( "In fi|
00000660  6e 61 6c 20 70 6f 73 69  74 69 6f 6e 22 20 29 0d  |nal position" ).|
00000670  03 52 17 20 f2 63 6f 6c  6f 75 72 28 20 3f 70 6f  |.R. .colour( ?po|
00000680  73 2c 20 33 20 29 0d 03  5c 0a 20 f2 77 61 69 74  |s, 3 )..\. .wait|
00000690  0d 03 66 0a 20 f2 77 69  70 65 0d 03 70 0b 20 3d  |..f. .wipe..p. =|
000006a0  20 3f 70 6f 73 0d 03 7a  05 20 0d 03 84 10 20 dd  | ?pos..z. .... .|
000006b0  20 f2 65 78 63 68 61 6e  67 65 0d 03 8e 17 20 f2  | .exchange.... .|
000006c0  6d 65 73 73 61 67 65 28  20 22 53 77 61 70 22 20  |message( "Swap" |
000006d0  29 0d 03 98 0a 20 f2 77  61 69 74 0d 03 a2 0a 20  |).... .wait.... |
000006e0  f2 77 69 70 65 0d 03 ac  1a 20 f2 73 77 61 70 28  |.wipe.... .swap(|
000006f0  20 70 6f 73 3f 30 2c 20  70 6f 73 3f 31 20 29 0d  | pos?0, pos?1 ).|
00000700  03 b6 1b 20 f2 63 6f 6c  6f 75 72 28 20 70 6f 73  |... .colour( pos|
00000710  3f 6d 6f 76 65 2c 20 38  20 29 0d 03 c0 14 20 6d  |?move, 8 ).... m|
00000720  6f 76 65 20 3d 20 6d 6f  76 65 20 82 20 31 0d 03  |ove = move . 1..|
00000730  ca 1b 20 f2 63 6f 6c 6f  75 72 28 20 70 6f 73 3f  |.. .colour( pos?|
00000740  6d 6f 76 65 2c 20 32 20  29 0d 03 d4 34 20 f1 20  |move, 2 )...4 . |
00000750  8a 20 64 65 70 74 68 20  2b 20 31 2c 20 70 6f 73  |. depth + 1, pos|
00000760  3f 30 20 2b 20 3f 61 74  20 29 20 73 77 61 70 24  |?0 + ?at ) swap$|
00000770  28 20 61 74 3f 70 6f 73  3f 30 20 29 3b 0d 03 de  |( at?pos?0 );...|
00000780  34 20 f1 20 8a 20 64 65  70 74 68 20 2b 20 31 2c  |4 . . depth + 1,|
00000790  20 70 6f 73 3f 31 20 2b  20 3f 61 74 20 29 20 73  | pos?1 + ?at ) s|
000007a0  77 61 70 24 28 20 61 74  3f 70 6f 73 3f 31 20 29  |wap$( at?pos?1 )|
000007b0  3b 0d 03 e8 06 20 e1 0d  03 f2 05 20 0d 03 fc 14  |;.... ..... ....|
000007c0  20 dd 20 f2 73 77 61 70  28 20 69 2c 20 6a 20 29  | . .swap( i, j )|
000007d0  0d 04 06 10 20 6b 65 65  70 20 3d 20 61 74 3f 69  |.... keep = at?i|
000007e0  0d 04 10 10 20 61 74 3f  69 20 3d 20 61 74 3f 6a  |.... at?i = at?j|
000007f0  0d 04 1a 10 20 61 74 3f  6a 20 3d 20 6b 65 65 70  |.... at?j = keep|
00000800  0d 04 24 06 20 e1 0d 04  2e 05 20 0d 04 38 0c 20  |..$. ..... ..8. |
00000810  dd 20 f2 65 61 73 79 0d  04 42 17 20 f2 63 6f 6c  |. .easy..B. .col|
00000820  6f 75 72 28 20 6c 61 73  74 2c 20 36 20 29 0d 04  |our( last, 6 )..|
00000830  4c 29 20 f2 6d 65 73 73  61 67 65 28 20 22 45 61  |L) .message( "Ea|
00000840  73 79 20 22 20 2b 20 73  69 64 65 24 20 2b 20 22  |sy " + side$ + "|
00000850  6c 69 73 74 22 20 29 0d  04 56 0a 20 f2 77 61 69  |list" )..V. .wai|
00000860  74 0d 04 60 17 20 f2 63  6f 6c 6f 75 72 28 20 6c  |t..`. .colour( l|
00000870  61 73 74 2c 20 33 20 29  0d 04 6a 0a 20 f2 77 69  |ast, 3 )..j. .wi|
00000880  70 65 0d 04 74 06 20 e1  0d 04 7e 05 20 0d 04 88  |pe..t. ...~. ...|
00000890  18 20 dd 20 f2 63 65 6e  74 72 65 28 20 74 69 74  |. . .centre( tit|
000008a0  6c 65 24 20 29 0d 04 92  1c 20 67 61 70 20 3d 20  |le$ ).... gap = |
000008b0  31 39 20 2d 20 a9 20 74  69 74 6c 65 24 20 81 20  |19 - . title$ . |
000008c0  32 0d 04 9c 19 20 f1 20  bd 20 26 38 33 20 89 20  |2.... . . &83 . |
000008d0  67 61 70 20 74 69 74 6c  65 24 0d 04 a6 06 20 e1  |gap title$.... .|
000008e0  0d 04 b0 05 20 0d 04 ba  0d 20 dd 20 f2 72 69 67  |.... .... . .rig|
000008f0  68 74 0d 04 c4 1a 20 e3  20 6c 6f 6f 70 20 3d 20  |ht.... . loop = |
00000900  66 69 72 73 74 20 b8 20  6c 61 73 74 0d 04 ce 32  |first . last...2|
00000910  20 f1 20 8a 20 64 65 70  74 68 2c 20 6c 6f 6f 70  | . . depth, loop|
00000920  20 2b 20 3f 61 74 20 29  20 22 20 22 20 77 6f 72  | + ?at ) " " wor|
00000930  64 24 28 20 61 74 3f 6c  6f 6f 70 20 29 3b 0d 04  |d$( at?loop );..|
00000940  d8 06 20 ed 0d 04 e2 06  20 e1 0d 04 ec 05 20 0d  |.. ..... ..... .|
00000950  04 f6 0c 20 dd 20 f2 6c  65 66 74 0d 05 00 1a 20  |... . .left.... |
00000960  e3 20 6c 6f 6f 70 20 3d  20 66 69 72 73 74 20 b8  |. loop = first .|
00000970  20 6c 61 73 74 0d 05 0a  32 20 f1 20 8a 20 64 65  | last...2 . . de|
00000980  70 74 68 2c 20 6c 6f 6f  70 20 2b 20 3f 61 74 20  |pth, loop + ?at |
00000990  29 20 77 6f 72 64 24 28  20 61 74 3f 6c 6f 6f 70  |) word$( at?loop|
000009a0  20 29 20 22 20 22 3b 0d  05 14 06 20 ed 0d 05 1e  | ) " ";.... ....|
000009b0  06 20 e1 0d 05 28 05 20  0d 05 32 1a 20 dd 20 f2  |. ...(. ..2. . .|
000009c0  63 6f 6c 6f 75 72 28 20  70 6f 73 2c 20 63 6f 6c  |colour( pos, col|
000009d0  20 29 0d 05 3c 22 20 ef  20 33 31 2c 20 30 2c 20  | )..<" . 31, 0, |
000009e0  70 6f 73 20 2b 20 3f 61  74 2c 20 63 6f 6c 20 84  |pos + ?at, col .|
000009f0  20 26 38 30 0d 05 46 06  20 e1 0d 05 50 05 20 0d  | &80..F. ...P. .|
00000a00  05 5a 0c 20 dd 20 f2 77  61 69 74 0d 05 64 0e 20  |.Z. . .wait..d. |
00000a10  64 75 6d 6d 79 20 3d 20  a5 0d 05 78 06 20 e1 0d  |dummy = ...x. ..|
00000a20  05 82 05 20 0d 05 8c 18  20 dd 20 f2 6d 65 73 73  |... .... . .mess|
00000a30  61 67 65 28 20 69 6e 66  6f 24 20 29 0d 05 96 12  |age( info$ )....|
00000a40  20 6c 65 6e 20 3d 20 a9  20 69 6e 66 6f 24 0d 05  | len = . info$..|
00000a50  a0 1c 20 f1 20 8a 20 34  30 20 2d 20 6c 65 6e 2c  |.. . . 40 - len,|
00000a60  20 34 20 29 20 69 6e 66  6f 24 0d 05 aa 06 20 e1  | 4 ) info$.... .|
00000a70  0d 05 b4 05 20 0d 05 be  0c 20 dd 20 f2 77 69 70  |.... .... . .wip|
00000a80  65 0d 05 c8 23 20 f1 20  8a 20 34 30 20 2d 20 6c  |e...# . . 40 - l|
00000a90  65 6e 2c 20 34 20 29 20  c4 20 6c 65 6e 2c 20 22  |en, 4 ) . len, "|
00000aa0  20 22 20 29 0d 05 d2 06  20 e1 0d 05 dc 05 20 0d  | " ).... ..... .|
00000ab0  05 e6 0c 20 dd 20 a4 65  78 69 74 0d 05 f0 19 20  |... . .exit.... |
00000ac0  f2 6d 65 73 73 61 67 65  28 20 22 41 67 61 69 6e  |.message( "Again|
00000ad0  3f 22 20 29 0d 05 fa 06  20 f5 0d 06 04 18 20 6b  |?" ).... ..... k|
00000ae0  65 79 20 3d 20 a7 20 22  59 79 4e 6e 22 2c 20 be  |ey = . "YyNn", .|
00000af0  20 29 0d 06 0e 0e 20 fd  20 6b 65 79 20 3e 20 30  | ).... . key > 0|
00000b00  0d 06 18 0a 20 f2 77 69  70 65 0d 06 22 0e 20 3d  |.... .wipe..". =|
00000b10  20 6b 65 79 20 3e 20 32  0d 06 2c 05 20 0d 06 36  | key > 2..,. ..6|
00000b20  14 20 dd 20 f2 69 6e 73  74 72 75 63 74 69 6f 6e  |. . .instruction|
00000b30  73 0d 06 40 1a 20 ef 20  32 33 3b 20 26 32 30 30  |s..@. . 23; &200|
00000b40  41 3b 20 30 3b 20 30 3b  20 30 3b 0d 06 4a 1d 20  |A; 0; 0; 0;..J. |
00000b50  f2 63 65 6e 74 72 65 28  20 22 49 6e 66 6f 72 6d  |.centre( "Inform|
00000b60  61 74 69 6f 6e 22 20 29  0d 06 54 1d 20 f2 63 65  |ation" )..T. .ce|
00000b70  6e 74 72 65 28 20 22 5f  5f 5f 5f 5f 5f 5f 5f 5f  |ntre( "_________|
00000b80  5f 5f 22 20 29 0d 06 5e  06 20 f1 0d 06 68 2d 20  |__" )..^. ...h- |
00000b90  f1 20 22 54 68 65 20 71  75 69 63 6b 73 6f 72 74  |. "The quicksort|
00000ba0  20 69 73 20 61 20 70 65  72 66 6f 72 6d 61 6e 63  | is a performanc|
00000bb0  65 20 73 6f 72 74 2e 22  0d 06 72 06 20 f1 0d 06  |e sort."..r. ...|
00000bc0  7c 32 20 f1 20 22 49 74  20 69 73 20 61 20 6e 61  ||2 . "It is a na|
00000bd0  74 75 72 61 6c 20 77 61  79 20 74 6f 20 73 6f 72  |tural way to sor|
00000be0  74 2e 20 49 66 20 79 6f  75 20 68 61 76 65 22 3b  |t. If you have";|
00000bf0  0d 06 86 30 20 f1 20 22  61 20 70 69 6c 65 20 6f  |...0 . "a pile o|
00000c00  66 20 63 61 72 64 73 20  77 68 69 63 68 20 6e 65  |f cards which ne|
00000c10  65 64 20 73 6f 72 74 69  6e 67 2c 20 79 6f 75 22  |ed sorting, you"|
00000c20  0d 06 90 2f 20 f1 20 22  74 6f 73 73 20 74 68 65  |.../ . "toss the|
00000c30  20 63 61 72 64 73 20 69  6e 74 6f 20 74 77 6f 20  | cards into two |
00000c40  6e 65 77 20 70 69 6c 65  73 2c 20 6f 6e 65 22 0d  |new piles, one".|
00000c50  06 9a 32 20 f1 20 22 66  6f 72 20 41 2d 4d 20 61  |..2 . "for A-M a|
00000c60  6e 64 20 74 68 65 20 6f  74 68 65 72 20 66 6f 72  |nd the other for|
00000c70  20 4e 2d 5a 2e 20 45 61  63 68 20 70 69 6c 65 22  | N-Z. Each pile"|
00000c80  3b 0d 06 a4 30 20 f1 20  22 69 73 20 66 75 72 74  |;...0 . "is furt|
00000c90  68 65 72 20 73 75 62 2d  64 69 76 69 64 65 64 20  |her sub-divided |
00000ca0  69 6e 20 74 68 65 20 73  61 6d 65 20 77 61 79 2e  |in the same way.|
00000cb0  22 0d 06 ae 06 20 f1 0d  06 b8 30 20 f1 20 22 49  |".... ....0 . "I|
00000cc0  74 20 69 73 20 71 75 69  63 6b 65 72 20 61 6e 64  |t is quicker and|
00000cd0  20 73 69 6d 70 6c 65 72  20 74 6f 20 73 6f 72 74  | simpler to sort|
00000ce0  20 73 6d 61 6c 6c 22 0d  06 c2 2f 20 f1 20 22 70  | small".../ . "p|
00000cf0  69 6c 65 73 2c 20 73 6f  20 74 68 69 73 20 69 73  |iles, so this is|
00000d00  20 61 20 73 75 63 63 65  73 73 66 75 6c 20 70 6f  | a successful po|
00000d10  6c 69 63 79 2e 22 0d 06  cc 06 20 f1 0d 06 d6 30  |licy.".... ....0|
00000d20  20 f1 20 22 54 68 65 20  63 6f 6d 70 75 74 65 72  | . "The computer|
00000d30  20 61 6c 67 6f 72 69 74  68 6d 20 75 73 65 73 20  | algorithm uses |
00000d40  73 6f 6d 65 20 63 6c 65  76 65 72 22 0d 06 e0 32  |some clever"...2|
00000d50  20 f1 20 22 6d 61 6e 69  70 75 6c 61 74 69 6f 6e  | . "manipulation|
00000d60  73 20 74 6f 20 65 78 65  63 75 74 65 20 71 75 69  |s to execute qui|
00000d70  63 6b 6c 79 2c 20 62 75  74 20 69 74 22 3b 0d 06  |ckly, but it";..|
00000d80  ea 28 20 f1 20 22 73 74  69 6c 6c 20 75 73 65 73  |.( . "still uses|
00000d90  20 74 68 65 20 73 61 6d  65 20 62 61 73 69 63 20  | the same basic |
00000da0  69 64 65 61 2e 22 0d 06  f4 06 20 f1 0d 06 fe 32  |idea.".... ....2|
00000db0  20 f1 20 22 49 6e 20 74  68 65 20 64 65 6d 6f 6e  | . "In the demon|
00000dc0  73 74 72 61 74 69 6f 6e  2c 20 69 74 20 69 73 20  |stration, it is |
00000dd0  69 6d 70 6f 72 74 61 6e  74 20 74 6f 22 3b 0d 07  |important to";..|
00000de0  08 2f 20 f1 20 22 6e 6f  74 69 63 65 20 74 68 61  |./ . "notice tha|
00000df0  74 20 74 68 65 20 6c 69  73 74 20 69 73 20 73 65  |t the list is se|
00000e00  70 61 72 61 74 65 64 20  69 6e 74 6f 22 0d 07 12  |parated into"...|
00000e10  2b 20 f1 20 22 6c 6f 77  65 72 20 26 20 68 69 67  |+ . "lower & hig|
00000e20  68 65 72 20 73 75 62 2d  6c 69 73 74 73 20 77 68  |her sub-lists wh|
00000e30  65 72 65 20 74 68 65 22  0d 07 1c 1b 20 f1 20 22  |ere the".... . "|
00000e40  70 6f 69 6e 74 65 72 73  20 63 6f 6e 76 65 72 67  |pointers converg|
00000e50  65 2e 22 0d 07 26 06 20  f1 0d 07 30 32 20 f2 63  |e."..&. ...02 .c|
00000e60  65 6e 74 72 65 28 20 22  50 72 65 73 73 20 61 20  |entre( "Press a |
00000e70  6b 65 79 20 74 6f 20 73  74 65 70 20 74 68 72 6f  |key to step thro|
00000e80  75 67 68 20 64 65 6d 6f  22 20 29 0d 07 3a 06 20  |ugh demo" )..:. |
00000e90  e1 0d 07 44 05 20 0d 07  4e 17 20 f4 20 20 20 20  |...D. ..N. .    |
00000ea0  20 4f 72 64 65 72 65 64  20 6c 69 73 74 0d 07 58  | Ordered list..X|
00000eb0  05 20 0d 07 62 10 20 dc  20 41 6c 67 6f 72 69 74  |. ..b. . Algorit|
00000ec0  68 6d 0d 07 6c 10 20 dc  20 42 6f 6f 74 73 74 72  |hm..l. . Bootstr|
00000ed0  61 70 0d 07 76 10 20 dc  20 43 6f 6e 76 65 72 74  |ap..v. . Convert|
00000ee0  65 72 0d 07 80 10 20 dc  20 44 69 72 65 63 74 6f  |er.... . Directo|
00000ef0  72 79 0d 07 8a 0f 20 dc  20 45 78 63 68 61 6e 67  |ry.... . Exchang|
00000f00  65 0d 07 94 10 20 dc 20  46 6c 6f 77 63 68 61 72  |e.... . Flowchar|
00000f10  74 0d 07 9e 0f 20 dc 20  47 72 61 70 68 69 63 73  |t.... . Graphics|
00000f20  0d 07 a8 0f 20 dc 20 48  61 72 64 77 61 72 65 0d  |.... . Hardware.|
00000f30  07 b2 10 20 dc 20 49 6e  74 65 72 66 61 63 65 0d  |... . Interface.|
00000f40  07 bc 0f 20 dc 20 4a 6f  79 73 74 69 63 6b 0d 07  |... . Joystick..|
00000f50  c6 0f 20 dc 20 4b 65 79  62 6f 61 72 64 0d 07 d0  |.. . Keyboard...|
00000f60  0f 20 dc 20 4c 61 6e 67  75 61 67 65 0d 07 da 10  |. . Language....|
00000f70  20 dc 20 4d 6e 65 6d 6f  6e 69 63 73 0d 07 e4 0f  | . Mnemonics....|
00000f80  20 dc 20 4e 65 67 61 74  69 76 65 0d 07 ee 10 20  | . Negative.... |
00000f90  dc 20 4f 70 65 72 61 74  69 6f 6e 0d 07 f8 0f 20  |. Operation.... |
00000fa0  dc 20 50 6f 73 69 74 69  76 65 0d 08 02 10 20 dc  |. Positive.... .|
00000fb0  20 51 75 69 63 6b 73 6f  72 74 0d 08 0c 10 20 dc  | Quicksort.... .|
00000fc0  20 52 65 63 75 72 73 69  6f 6e 0d 08 16 0f 20 dc  | Recursion.... .|
00000fd0  20 53 6f 66 74 77 61 72  65 0d 08 20 0f 20 dc 20  | Software.. . . |
00000fe0  54 65 6c 65 74 65 78 74  0d ff                    |Teletext..|
00000fea
18-06-89/QSDemo.m0
18-06-89/QSDemo.m1
18-06-89/QSDemo.m2
18-06-89/QSDemo.m4
18-06-89/QSDemo.m5