home *** CD-ROM | disk | FTP | other *** search
- \ 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
-
- 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
-