Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1,18 @@
|
|||
(defun insertion-sort (sequence &optional (predicate #'<))
|
||||
(if (cdr sequence)
|
||||
(insert (car sequence) ;; insert the current item into
|
||||
(insertion-sort (cdr sequence) ;; the already-sorted
|
||||
predicate) ;; remainder of the list
|
||||
predicate)
|
||||
sequence)) ; a list of one element is already sorted
|
||||
|
||||
(defun insert (item sequence predicate)
|
||||
(cond ((null sequence) (list item))
|
||||
((funcall (complement predicate) ;; if the first element of the list
|
||||
(car sequence) ;; isn't better than the item,
|
||||
item) ;; cons the item onto
|
||||
(cons item sequence)) ;; the front of the list
|
||||
(t (cons (car sequence) ;; otherwise cons the first element onto the front of
|
||||
(insert item ;; the list of the item sorted with the rest of the list
|
||||
(cdr sequence)
|
||||
predicate)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue