next up previous contents
Next: 'insertion-sort' Up: Insertion Sort Previous: Insertion Sort   Contents

sorted insertion into a list


(define insert (lambda(x l)
                 (if (nullp l)
                     (cons x nil)
                     (if (ltp x (car l))
                       (cons x l)
                       (cons (car l) 
                             (insert x (cdr l)))))))


(define l1 (cons one (cons three (cons four nil))))
;
(ldisp! (insert two l1))
                             --> 1
                                 2
                                 3
                                 4



Georg P. Loczewski 2004-03-05


Impressum und Datenschutz