Created
May 30, 2011 18:40
-
-
Save zard1989/999290 to your computer and use it in GitHub Desktop.
insertion sort in common lisp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun insert (item lst &optional (key #'<)) | |
(if (null lst) | |
(list item) | |
(if (funcall key item (car lst)) | |
(cons item lst) | |
(cons (car lst) (insert item (cdr lst) key))))) | |
(defun insertion-sort (lst &optional (key #'<)) | |
(if (null lst) | |
lst | |
(insert (car lst) (insertion-sort (cdr lst) key) key))) | |
(insertion-sort '(1 4 2 4 5 1 3 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you.