comp.lang.ada
 help / color / mirror / Atom feed
From: "chris.danx" <chris.danx@ntlworld.com>
Subject: Re: A little help with Quicksort
Date: Wed, 2 Jan 2002 00:53:02 -0000
Date: 2002-01-02T00:53:02+00:00	[thread overview]
Message-ID: <cRsY7.25325$Zg2.2628242@news11-gui.server.ntli.net> (raw)
In-Reply-To: 1408ce1d.0201011425.29c12c97@posting.google.com


"Mond" <mrsmond@hotmail.com> wrote in message
news:1408ce1d.0201011425.29c12c97@posting.google.com...
> Hi,

Hi,

> i'm having a little trouble implementing Quicksort with a doubley
> linked list and was hoping someone could put me in the right direction
> ;)

Sure.  I'll try but I can't give you much help because I am doing a very
similar exercise for next week.


> The part marked with stars above is a wee bit confusing.
>
> Why does it swap the pivot value? Is it so that when QSort is called
> again the pivot value remains on the left hand side?

Yes.  If the pivot ended up in the righthand side then it would always be
chosen, and the QSort would never terminate or cause a stack overflow (the
pivot and all the members of the righthand side are >= pivot).


> This works with arrays but converting it into working with a linked
> list is a bit harder.

Do you undestrand the algorithm and it's solution (for arrays)?  Converting
the array solution to lists like that will not work, or at least not as
easily as it would if you take the main points (choose pivot, partition,
sort) of the algorithm and coded them.  My suggestion is to break the list
into two lists, and don't try to move the pointers about.


> PS Sorry for all the .all etc stuff - it makes it clear to me that it
> is pointers ;)

It's a matter of style, and there's nothing wrong with it.


Hope this helps,
Chris





  reply	other threads:[~2002-01-02  0:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-01 22:25 A little help with Quicksort Mond
2002-01-02  0:53 ` chris.danx [this message]
2002-01-02 13:11   ` Ted Dennison
2002-01-02 22:22   ` Mond
2002-01-03 14:54     ` chris.danx
2002-01-03 15:42       ` Ted Dennison
2002-01-24 23:14         ` Craig Carey
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox