15. Alphabetic sort ~~~~~~~~~~~~~~~ This is a very fast BASIC Sort Procedure, known as a Shell-Metzner Sort. It is far faster than a simple Bubble Sort on long lists, and can sort a several hundred names in only a few seconds. It can just be beaten by the Quicksort published in the November 1982 Beebug. However, the Quicksort uses recursion, which means you can't easily add any bits of your own in the Procedure without the routine hanging up, so I prefer to stick with this one. It assumes that you have a list of names, or whatever, in an array called file$, (or A$ etc. if you prefer). If you have DIMensioned the array as file$(300), and it's always full up, then you would use PROCsort(300), otherwise substitute a variable giving the last element with anything in it. If you want the list in descending alphabetical order, then change the "<=" in line 160 to ">=". As usual, all the variables except file$ itself are LOCAL, so can be used elsewhere without any clash. Unless you 'fill up' the whole array initially with strings of the maximum length likely to be encountered, then the Sort is bound to gobble up memory in use. This isn't the fault of the Procedure, but is a quirk of BBC BASIC, known as poor 'Garbage Collecting'. The Procedure can easily be adapted to sort numbers instead of strings, in which case this problem doesn't arise. 100 DEFPROCsort(extent%) 110 LOCAL I%,J%,K%,L%,M%,swap$:M%=extent% 120 M%=M%DIV2:IF M%=0 THEN 200 130 K%=extent%-M%:J%=1 140 I%=J% 150 L%=I%+M% 160 IF file$(I%)<=file$(L%) THEN 190 170 swap$=file$(I%):file$(I%)=file$(L%):file$(L%)=swap$ 180 I%=I%-M%:IF I%>0 THEN 150 190 J%=J%+1:IF J%>K% THEN 120 ELSE 140 200 ENDPROC