Re: qsort optimized for brevity
- From: "Marc Battyani" <Marc.Battyani@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Dec 2005 23:42:08 +0100
"Marc Battyani" <Marc.Battyani@xxxxxxxxxxxxxxxxxx> wrote
> <nallen05@xxxxxxxxx> wrote
> > noone said it had to be fast right? ; - )
> >
> > (defun qsort (list &optional 2nd)
> > (if (null list)
> > 2nd
> > (let ((max (eval (cons 'max list))))
>
> The eval will be really slow and the evaluation of max will crash if list is too big.
> You should use (reduce 'max list) instead.
>
> But don't worry it will be slow enough anyway ;-)
In fact I would rewrite it that way:
(note that it's not a quick sort anymore)
(defun qsort (list)
(when list
(let ((max (reduce 'max list)))
(cons max (qsort (remove max list :count 1))))))
(qsort '(1 5 3 2 4 6 8 4 5 6 1 5))
(8 6 6 5 5 5 4 4 3 2 1 1)
Marc
.
- References:
- qsort optimized for brevity
- From: justinhj
- Re: qsort optimized for brevity
- From: Greg Buchholz
- Re: qsort optimized for brevity
- From: Bruce Hoult
- Re: qsort optimized for brevity
- From: nallen05
- Re: qsort optimized for brevity
- From: Marc Battyani
- qsort optimized for brevity
- Prev by Date: Re: qsort optimized for brevity
- Next by Date: Re: Do I have to be an expert to get performance: CL versus Perl
- Previous by thread: Re: qsort optimized for brevity
- Next by thread: Re: qsort optimized for brevity
- Index(es):
Relevant Pages
|