Home » Archimedes archive » Micro User » MU 1991-09.adf » PD-Stuff » FracTrace/FTS-Files/Bubble

FracTrace/FTS-Files/Bubble

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 » Archimedes archive » Micro User » MU 1991-09.adf » PD-Stuff
Filename: FracTrace/FTS-Files/Bubble
Read OK:
File size: 02D3 bytes
Load address: 0000
Exec address: 0000
File contents
\ Bubblesort
\ The famous sorting routine in FTS

\ declare variables to be used

var min, max, cnt, loop, help

\ set minimum and maximum of interval to sort on

min=50; max=55

\ set [min..max] to a random number
\ the array v(i) may be used as long as the index i
\ is greater than the number of user-vars. and smaller
\ than 100 !!!

for cnt=min to max
 v(cnt)=RND(1000)
endfor

\ the actual sorting loops

for cnt=max to min+1 by -1
 for loop=min to cnt-1
  if v(loop)>v(loop+1)
   call swap
  endif
 endfor
endfor

\ show the sorted array and stop

for cnt=min to max
 show v(cnt)
endfor
stop

\ subroutine to swap two consecutive elements in the array

.swap
 help=v(loop)
 v(loop)=v(loop+1)
 v(loop+1)=help
 return
00000000  5c 20 42 75 62 62 6c 65  73 6f 72 74 0a 5c 20 54  |\ Bubblesort.\ T|
00000010  68 65 20 66 61 6d 6f 75  73 20 73 6f 72 74 69 6e  |he famous sortin|
00000020  67 20 72 6f 75 74 69 6e  65 20 69 6e 20 46 54 53  |g routine in FTS|
00000030  0a 0a 5c 20 64 65 63 6c  61 72 65 20 76 61 72 69  |..\ declare vari|
00000040  61 62 6c 65 73 20 74 6f  20 62 65 20 75 73 65 64  |ables to be used|
00000050  0a 0a 76 61 72 20 6d 69  6e 2c 20 6d 61 78 2c 20  |..var min, max, |
00000060  63 6e 74 2c 20 6c 6f 6f  70 2c 20 68 65 6c 70 0a  |cnt, loop, help.|
00000070  0a 5c 20 73 65 74 20 6d  69 6e 69 6d 75 6d 20 61  |.\ set minimum a|
00000080  6e 64 20 6d 61 78 69 6d  75 6d 20 6f 66 20 69 6e  |nd maximum of in|
00000090  74 65 72 76 61 6c 20 74  6f 20 73 6f 72 74 20 6f  |terval to sort o|
000000a0  6e 0a 0a 6d 69 6e 3d 35  30 3b 20 6d 61 78 3d 35  |n..min=50; max=5|
000000b0  35 0a 0a 5c 20 73 65 74  20 5b 6d 69 6e 2e 2e 6d  |5..\ set [min..m|
000000c0  61 78 5d 20 74 6f 20 61  20 72 61 6e 64 6f 6d 20  |ax] to a random |
000000d0  6e 75 6d 62 65 72 0a 5c  20 74 68 65 20 61 72 72  |number.\ the arr|
000000e0  61 79 20 76 28 69 29 20  6d 61 79 20 62 65 20 75  |ay v(i) may be u|
000000f0  73 65 64 20 61 73 20 6c  6f 6e 67 20 61 73 20 74  |sed as long as t|
00000100  68 65 20 69 6e 64 65 78  20 69 0a 5c 20 69 73 20  |he index i.\ is |
00000110  67 72 65 61 74 65 72 20  74 68 61 6e 20 74 68 65  |greater than the|
00000120  20 6e 75 6d 62 65 72 20  6f 66 20 75 73 65 72 2d  | number of user-|
00000130  76 61 72 73 2e 20 61 6e  64 20 73 6d 61 6c 6c 65  |vars. and smalle|
00000140  72 0a 5c 20 74 68 61 6e  20 31 30 30 20 21 21 21  |r.\ than 100 !!!|
00000150  0a 0a 66 6f 72 20 63 6e  74 3d 6d 69 6e 20 74 6f  |..for cnt=min to|
00000160  20 6d 61 78 0a 20 76 28  63 6e 74 29 3d 52 4e 44  | max. v(cnt)=RND|
00000170  28 31 30 30 30 29 0a 65  6e 64 66 6f 72 0a 0a 5c  |(1000).endfor..\|
00000180  20 74 68 65 20 61 63 74  75 61 6c 20 73 6f 72 74  | the actual sort|
00000190  69 6e 67 20 6c 6f 6f 70  73 0a 0a 66 6f 72 20 63  |ing loops..for c|
000001a0  6e 74 3d 6d 61 78 20 74  6f 20 6d 69 6e 2b 31 20  |nt=max to min+1 |
000001b0  62 79 20 2d 31 0a 20 66  6f 72 20 6c 6f 6f 70 3d  |by -1. for loop=|
000001c0  6d 69 6e 20 74 6f 20 63  6e 74 2d 31 0a 20 20 69  |min to cnt-1.  i|
000001d0  66 20 76 28 6c 6f 6f 70  29 3e 76 28 6c 6f 6f 70  |f v(loop)>v(loop|
000001e0  2b 31 29 0a 20 20 20 63  61 6c 6c 20 73 77 61 70  |+1).   call swap|
000001f0  0a 20 20 65 6e 64 69 66  0a 20 65 6e 64 66 6f 72  |.  endif. endfor|
00000200  0a 65 6e 64 66 6f 72 0a  0a 5c 20 73 68 6f 77 20  |.endfor..\ show |
00000210  74 68 65 20 73 6f 72 74  65 64 20 61 72 72 61 79  |the sorted array|
00000220  20 61 6e 64 20 73 74 6f  70 0a 0a 66 6f 72 20 63  | and stop..for c|
00000230  6e 74 3d 6d 69 6e 20 74  6f 20 6d 61 78 0a 20 73  |nt=min to max. s|
00000240  68 6f 77 20 76 28 63 6e  74 29 0a 65 6e 64 66 6f  |how v(cnt).endfo|
00000250  72 0a 73 74 6f 70 0a 0a  5c 20 73 75 62 72 6f 75  |r.stop..\ subrou|
00000260  74 69 6e 65 20 74 6f 20  73 77 61 70 20 74 77 6f  |tine to swap two|
00000270  20 63 6f 6e 73 65 63 75  74 69 76 65 20 65 6c 65  | consecutive ele|
00000280  6d 65 6e 74 73 20 69 6e  20 74 68 65 20 61 72 72  |ments in the arr|
00000290  61 79 0a 0a 2e 73 77 61  70 0a 20 68 65 6c 70 3d  |ay...swap. help=|
000002a0  76 28 6c 6f 6f 70 29 0a  20 76 28 6c 6f 6f 70 29  |v(loop). v(loop)|
000002b0  3d 76 28 6c 6f 6f 70 2b  31 29 0a 20 76 28 6c 6f  |=v(loop+1). v(lo|
000002c0  6f 70 2b 31 29 3d 68 65  6c 70 0a 20 72 65 74 75  |op+1)=help. retu|
000002d0  72 6e 0a                                          |rn.|
000002d3