home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / mutt / sort.mut < prev    next >
Text File  |  1988-03-01  |  937b  |  42 lines

  1. (defun 
  2.   sort (array int list 1)(int n)    ; shell sort an array of n ints
  3.   {
  4.     (int gap i j t k)
  5.     (gap (/ n 2))
  6.     (while (> gap 0)
  7.     {
  8.       (i gap)
  9.       (while (< i n)
  10.       {
  11.     (j (- i gap))
  12.     (while (and (>= j 0) (> (list j)(list (+ j gap))))
  13.     {
  14.       (k (+ j gap))(t (list j))(list j (list k))(list k t)
  15.       (-= j gap)
  16.     })
  17.         (+= i 1)
  18.       })
  19.       (/= gap 2)
  20.     })
  21.   }
  22. )
  23.  
  24.  
  25. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  26. ;;;;;;;;;;;;;;;;;  test ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  27. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  28.  
  29. (include random.mut)
  30.  
  31. (array int list 501) (int n j)
  32. (n (atoi (ask "n = ")))
  33.  
  34. (for (j 0) (< j n)(+= j 1) (list j (rand)))
  35.  
  36. (for (j 0)(< j n)(+= j 1) (msg "list[" j "] = " (list j)))
  37. (sort list n)
  38. (msg "--------------------------")
  39. (for (j 0)(< j n)(+= j 1) (msg "list[" j "] = " (list j)))
  40.  
  41.  
  42.