Skip to content

Instantly share code, notes, and snippets.

@zard1989
Created July 3, 2010 16:25
Show Gist options
  • Select an option

  • Save zard1989/462670 to your computer and use it in GitHub Desktop.

Select an option

Save zard1989/462670 to your computer and use it in GitHub Desktop.
(defun insert (cmp target list)
"Insert the target into a sorted list."
(if (null list)
(cons target '())
(if (funcall cmp target (first list))
(cons target list)
(cons (first list) (insert cmp target (rest list))))))
(defun insertionSort (cmp list)
"Insertion Sort, a recursive version."
(if (null list)
'()
(insert cmp (first list) (insertionSort cmp (rest list)))))
(defun quickSort (cmp list)
"Quicksort...usage: (quickSort #'< list)"
(cond
((null list) '())
(T (let* ((x (first list))
(less (remove-if-not #'(lambda (y) (funcall cmp y x)) list))
(greater (remove-if-not #'(lambda (y) (funcall cmp x y)) list)))
(append (quickSort cmp less) (cons x (quickSort cmp greater)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment