home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples1.exe / CLisp / sort.lisp < prev    next >
Encoding:
Text File  |  2000-06-23  |  757 b   |  28 lines

  1. (defun Length (LIST) (if (null LIST)
  2.                          0
  3.                          (+ 1 (Length (cdr LIST)))))
  4.  
  5. (defun Remove (L e) 
  6.   (do ((lst L (cdr lst))
  7.        (c (if (= (car lst) (car e)) 'NIL (car lst))
  8.           (if (= (car lst) (car e)) c (cons c (car lst)))))
  9.       ((null lst) c)
  10.       ((= (car lst) (car e)) 
  11.        (cons c (cdr lst)))))
  12.  
  13. (defun Sort (X) 
  14.   (do ((lst X (Remove lst (do ((lst1 lst (cdr lst1))
  15.                (min (car lst) (if (< (car min) (car lst1)) min (car lst1))))
  16.               ((null (cdr lst1))
  17.                min))))
  18.        (count (Length X) (- count 1))
  19.        (Srt 'NIL (cons Srt min)))
  20.       ((= count 0)
  21.        Srt)))
  22.  
  23.              
  24. (Sort '(5 1 10))
  25.  
  26. (Sort '(-11 8 15 67 19 11 10 9 8 7 1 100 200 300 6 5 0 4 3 2 1 0))
  27.  
  28.