Created
January 5, 2019 18:33
-
-
Save candh/e75e4d56b30733a421e400b8d2d87bef to your computer and use it in GitHub Desktop.
elisp quicksort
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
| ;; 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