[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

None



<htang#a#news#d#cis#d#ohio-state#d#edu.METRON#u#CA@uu0841.ca.metsci.com>
CC: "Info MCL" <info-mcl@cambridge.apple.com>

                       Subject:                               Time:2:28 PM
  OFFICE MEMO          None                                   Date:5/26/93
 >Hi,
 >   I am currently learning common lisp. It seems to me that lisp is pretty
hard 
 > to handle more complex algorithm, although its syntax looks easier.
 >
 >   I'd like to implement a sort(insertion and selection)  function using
simple 
 > simple functions like DEFUN, CAR, CDR, >, LAMBDA, ... etc. However, I never
got 
 > my sort function work. I know lisp has a sort function provided but i like to
> see the actual imlementation.
 >
 >
 >If anyone has a sort function(any), can you send me a copy?
 >OR if you know how to implement one easily, can you drop me a line?
 >
 >thanks for any help
 >
 >htang@cis.ohio-state.edu

The following ought to do a single insertion into a list of integers.  A full
insertion sort using this should be easy enough.

(defun insert (item list)
  (cond ((null list) (list item))
           ((< item (car list)) (cons item list))
           (t (cons (car list) (insert item (cdr list))))
        )
  )
 ie (insert 3 '(1 2 4 5)) -> '(1 2 3 4 5)

Jeff Monroe