Sorting algorithms/Insertion sort: Difference between revisions
Sorting algorithms/Insertion sort (view source)
Revision as of 20:28, 11 December 2007
, 16 years agoAdded CL version
(Haskell Example) |
(Added CL version) |
||
Line 12:
Writing the algorithm for integers will suffice.
=={{header|Common Lisp}}==
(defun span (predicate list)
(let ((tail (member-if-not predicate list)))
(values (ldiff list tail) tail)))
(defun less-than (x)
(lambda (y) (< y x)))
(defun insert (list elt)
(multiple-value-bind (left right) (span (less-than elt) list)
(append left (list elt) right)))
(defun insertion-sort (list)
(reduce #'insert list :initial-value nil))
=={{header|Haskell}}==
|