The following procedure receives an array containing data to be sorted. The zero element will contain
the number of items. Note that it does not matter whether the array is numeric or string. The principle
of coercion will change string to numeric data if necessary.
A second point of interest is that the array element, come(0), is used for two purposes:
it carries the number of items to be sorted
it is used to hold the item currently being placed.
100 DEFine PROCedure sort(come,send)
110 LET num = come(0)
120 FOR item = 2 TO num
130 LET p = item
140 LET come(0) = come(p)
150 REPeat compare
160 IF come(0) >= come(p-1) : EXIT compare
170 LET come(p) = come(p-1)
180 LET p = p - 1
190 END REPeat compare
200 LET come(p) = come(0)
210 END FOR item
220 FOR k = 1 TO 7 : send(k) = come(k)
230 END DEFine
The following additional lines will test the sort procedure. First type AUTO 10 to start the
line numbers from 10 onwards.
10 REMark Test Sort
20 DIM row$(7,3),back$(7,3)
30 LET row$(0) = 7
40 FOR k = 1 TO 7 : READ row$(k)
50 sort row$,back$
60 PRINT ! back$ !
70 DATA "EEL","DOG","ANT","GNU","CAT","BUG","FOX"
Output
ANT BUG CAT DOG EEL FOX GNU
COMMENT
This program illustrates how easily you can handle arrays in SuperBASIC. All you have to do is use
the array names for passing them as parameters or for printing the whole array. Once the procedure
is saved you can use MERGE mdv1_sort to add it to a program in main memory.
You now have enough understanding of techniques and syntax to handle a more complex screen
layout. Suppose you wish to represent the hands of four card players. A hand can be represented by
something like:
H: A 3 7 Q
C: 5 9 J
D: 6 10 K
S: 2 4 Q
To help the presentation the Hearts and Diamonds will be printed in red and the Clubs and Spades in
black. A suitable STRIP colour might be white. The general background could be green and a table
may be a colour obtained by mixing two colours.
METHOD