home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / fractals / _fractrace / FTS-Files / Bubble next >
Encoding:
Text File  |  1990-07-21  |  601 b   |  42 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.  
  14. for cnt=min to max
  15.  v(cnt)=RND(1000)
  16. endfor
  17.  
  18. \ the actual sorting loops
  19.  
  20. for cnt=max to min+1 by -1
  21.  for loop=min to cnt-1
  22.   if v(loop)>v(loop+1)
  23.    call swap
  24.   endif
  25.  endfor
  26. endfor
  27.  
  28. \ show the sorted array and stop
  29.  
  30. for cnt=min to max
  31.  show v(cnt)
  32. endfor
  33. stop
  34.  
  35. \ subroutine to swap two consecutive elements in the array
  36.  
  37. .swap
  38.  help=v(loop)
  39.  v(loop)=v(loop+1)
  40.  v(loop+1)=help
  41.  return
  42.