Skip to content

Instantly share code, notes, and snippets.

@zard1989
Created May 30, 2011 18:40
Show Gist options
  • Save zard1989/999290 to your computer and use it in GitHub Desktop.
Save zard1989/999290 to your computer and use it in GitHub Desktop.
insertion sort in common lisp
(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))
@Kunjung
Copy link

Kunjung commented Mar 17, 2016

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment