Skip to content

Instantly share code, notes, and snippets.

@toctan
Created June 21, 2014 03:28
Show Gist options
  • Save toctan/9b515faac43097e6f455 to your computer and use it in GitHub Desktop.
Save toctan/9b515faac43097e6f455 to your computer and use it in GitHub Desktop.
(defun quicksort (vec l r)
(let ((i l)
(j r)
(p (svref vec (round (+ l r) 2))))
(while (<= i j)
(while (< (svref vec i) p) (incf i))
(while (> (svref vec j) p) (decf j))
(when (<= i j)
(rotatef (svref vec i) (svref vec j))
(incf i)
(decf j)))
(if (> j l) (quicksort vec l j))
(if (> r i) (quicksort vec i r)))
(princ vec)
(terpri)
vec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment