(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) 1) (quicksort vec l j)) (if (> (- r i) 1) (quicksort vec i r))) vec) ;(defmacro while (test &rest body) ; `(do () ; ((not ,test)) ; ,@body)) (deftest test-quicksort() (check (equal "#(1 2 4 6 7 9 8)" (format nil "~A" (quicksort (vector 8 9 4 2 6 7 1) 0 6))) (equal "#(0 1 2 4 3 5 6 7 8 9 10)" (format nil "~A" (quicksort (vector 10 9 8 7 6 5 3 4 2 1 0) 0 10))) ))