quick sort

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.
Post Reply
omarasl
Posts: 12
Joined: Sun Nov 25, 2012 6:19 am

quick sort

Post by omarasl » Tue Dec 11, 2012 7:46 am

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

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: quick sort

Post by Goheeca » Tue Dec 11, 2012 9:44 am

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.

sylwester
Posts: 133
Joined: Mon Jul 11, 2011 2:53 pm

Re: quick sort

Post by sylwester » Tue Dec 11, 2012 5:15 pm

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
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p

Post Reply