Skip to content

Instantly share code, notes, and snippets.

@candh
Created January 5, 2019 18:33
Show Gist options
  • Select an option

  • Save candh/e75e4d56b30733a421e400b8d2d87bef to your computer and use it in GitHub Desktop.

Select an option

Save candh/e75e4d56b30733a421e400b8d2d87bef to your computer and use it in GitHub Desktop.
elisp quicksort
;; https://harryrschwartz.com/2014/04/08/an-introduction-to-emacs-lisp.html
;; this is amazing
(require 'cl-remove-if-not)
(defun quicksort (items)
(if (null items)
nil
(let* ((pivot (car items))
(rest (cdr items))
(lesser (cl-remove-if-not (lambda (x) (<= x pivot)) rest))
(greater (cl-remove-if-not (lambda (x) (> x pivot)) rest)))
(append (quicksort lesser) (list pivot) (quicksort greater)))))
(quicksort `(5 8 3 0 4 7 2 1 4 3 5 9))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment