home *** CD-ROM | disk | FTP | other *** search
/ Really Useful CD 1 / ReallyUsefulCD1.iso / extras / graphics / fractrace / fts_files / bubble next >
Encoding:
Text File  |  1990-08-02  |  723 b   |  45 lines

  1. \ Bubblesort
  2. \ The famous sorting routine in FTS
  3.  
  4. \ declare variables to be used
  5.  
  6. var min, max, cnt, loop, help
  7.  
  8. \ set minimum and maximum of interval to sort on
  9.  
  10. min=50; max=55
  11.  
  12. \ set [min..max] to a random number
  13. \ the array v(i) may be used as long as the index i
  14. \ is greater than the number of user-vars. and smaller
  15. \ than 100 !!!
  16.  
  17. for cnt=min to max
  18.  v(cnt)=RND(1000)
  19. endfor
  20.  
  21. \ the actual sorting loops
  22.  
  23. for cnt=max to min+1 by -1
  24.  for loop=min to cnt-1
  25.   if v(loop)>v(loop+1)
  26.    call swap
  27.   endif
  28.  endfor
  29. endfor
  30.  
  31. \ show the sorted array and stop
  32.  
  33. for cnt=min to max
  34.  show v(cnt)
  35. endfor
  36. stop
  37.  
  38. \ subroutine to swap two consecutive elements in the array
  39.  
  40. .swap
  41.  help=v(loop)
  42.  v(loop)=v(loop+1)
  43.  v(loop+1)=help
  44.  return
  45.