3 ms·
Lisp is imperative. This is actual standard Common Lisp and basically the same (minus slightly different syntax) as the quicksort example from the link: (
by lispm 6y ago
Lisp is imperative.
This is actual standard Common Lisp and basically the same (minus slightly different syntax) as the quicksort example from the link:
(defun qksort-inplace (a lo hi)
(declare (type integer lo hi)
(type (array float) a))
(if (>= lo hi)
(return-from qksort-inplace))
(let ((pivot (aref a lo))
(left lo)
(right hi))
(declare (type float pivot)
(type integer lo hi))
(loop while (<= left right) do
(loop while (< (aref a left) pivot) do
(setf left (+ left 1)))
(loop while (> (aref a right) pivot) do
(setf right (- right 1)))
(if (<= left right)
(let ((tmp (aref a left)))
(setf (aref a left) (aref A right)
(aref a right) tmp
left (+ left 1)
right (- right 1)))))
(qksort-inplace A lo right)
(qksort-inplace A left hi)))
- konjin 6y agoCan be is not is. One can rewrite that in a functional not implace style. Less so for a language with a c like call stack. Which is why the op wrote it like that instead of using tail call recursion.