Page 1 of 1

quick sort

Posted: Tue Dec 11, 2012 7:46 am
by omarasl
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

Posted: Tue Dec 11, 2012 9:44 am
by Goheeca
And how does the implementation of list< and list>= functions look?

Re: quick sort

Posted: Tue Dec 11, 2012 5:15 pm
by sylwester
I haven't changed your code, just put it in code-tags. I tested it and it works.

Code: Select all

(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