This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

quick sort

3 posts · 6183 views

hello every body ,
I tried to sort a list by using the quick sort algorithm
I put this code but I can not get the result

(defun qsort (L)
(if (null L)
nil
(append
(qsort (list< (first L) (rest L)) )
(cons (first L) nil)
(qsort (list>= (first L) (rest L)) )
)
)
)

would some one help me please with this code or if there is another code to do that

Re: quick sort

And how does the implementation of list< and list>= functions look?
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Re: quick sort

I haven't changed your code, just put it in code-tags. I tested it and it works.
(defun qsort (L)
   (if (null L)
       nil
      (append
                  (qsort (list< (first L) (rest L)))
                  (cons (first L) nil)
                  (qsort (list>= (first L) (rest L))))))
You need to define list< and list>= as well since it's a large part that's obviously missing but if they return lists lower and higher than the first element you have (numeric) quick sort :D
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p