Velocity Reviews > How to use qsort function of C library ?

How to use qsort function of C library ?

pereges
Guest
Posts: n/a

 04-08-2008
It is not explained well in my manual. can someone please tell me
about it ?

Is qsort the best sorting algorithm out there ?

pereges
Guest
Posts: n/a

 04-08-2008
I actually need to sort a set of vertices each having x, y, z
coordinates but then I have to sort the records according to x
coordinate, y coordinate or z.

Walter Roberson
Guest
Posts: n/a

 04-08-2008
In article <(E-Mail Removed)>,
pereges <(E-Mail Removed)> wrote:
>It is not explained well in my manual. can someone please tell me
>about it ?

>Is qsort the best sorting algorithm out there ?

No.
http://en.wikipedia.org/wiki/Sorting_algorithm

Notice that the worst case for quick sort is O(n^2). There are a
number of other algorithms listed there whose worst case is O(n*log(n))

See also the mention of "Simple pancake sort", and of "Han's algorithm".

--
"The whole history of civilization is strewn with creeds and
institutions which were invaluable at first, and deadly
afterwards." -- Walter Bagehot

Keith Thompson
Guest
Posts: n/a

 04-08-2008
pereges <(E-Mail Removed)> writes:
> It is not explained well in my manual. can someone please tell me
> about it ?
>
> Is qsort the best sorting algorithm out there ?

You appear to be the same person who's been posting as "broli".
Please use a consistent name when posting here.

Please put your question in the body of the message. Not all
newsreaders show the subject header in a way that makes it easy to
see.

qsort is not an algorithm, it's an interface specified by the C
standard. Different implementations of qsort can use different
algorithms. (The name was originally derived from "quicksort", but
there's no requirement for qsort to use the quicksort algorithm.)

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Keith Thompson
Guest
Posts: n/a

 04-08-2008
pereges <(E-Mail Removed)> writes:
> It is not explained well in my manual. can someone please tell me
> about it ?
>
> Is qsort the best sorting algorithm out there ?

I forgot to mention, there are examples of using qsort() in section 13
of the comp.lang.c FAQ, <http://www.c-faq.com/>.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Willem
Guest
Posts: n/a

 04-08-2008
Walter wrote:
) In article <(E-Mail Removed)>,
) pereges <(E-Mail Removed)> wrote:
)>It is not explained well in my manual. can someone please tell me
)>about it ?
)
)>Is qsort the best sorting algorithm out there ?
)
) No.
) <snip>

qsort, in this context, is not an algorithm. It *uses* an algorithm,
but it's free for the implementor to decide which one (or ones).

SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

Chris McDonald
Guest
Posts: n/a

 04-09-2008
CBFalconer <(E-Mail Removed)> writes:

>pereges wrote:
>>
>> It is not explained well in my manual. can someone please tell me
>> about it ?

>'it' is a pronoun, normally used to refer to a noun used earlier in
>the paragraph.

The noun appeared in the Subject: line,
clearly referring to qsort and not the library.

--
Chris.

pereges
Guest
Posts: n/a

 04-09-2008
I think in this case I will be better of writing an sorting function
of my own. my array is a buffer of vertices where each vertex is
actually a struct having a x, y and z component. i need to sort the
records according to x coordinate or y coordinate or z coordinate. i
don't think you can use qsort to accomplish this.

Ben Bacarisse
Guest
Posts: n/a

 04-09-2008
pereges <(E-Mail Removed)> writes:

> I think in this case I will be better of writing an sorting function
> of my own. my array is a buffer of vertices where each vertex is
> actually a struct having a x, y and z component. i need to sort the
> records according to x coordinate or y coordinate or z coordinate. i
> don't think you can use qsort to accomplish this.

I think you can. Do you mean sort by x sometimes and by y other
times? If that is the case, you just need three comparison
functions. You could have just one with a global "coordinate" picking
variable, but the three function route is simpler.

--
Ben.

pereges
Guest
Posts: n/a

 04-09-2008
On Apr 9, 9:53 am, Richard Heathfield <(E-Mail Removed)> wrote:

>
> Well, actually you can, provided that you can define an ordering
> relationship between two vertices. For example, let us say that we want to
> order by x first, by y if x1==x2, and by z if x1==x2 and y1==y2. We do it
> like this:
>

What is this ordering relationship ? Why should we sort along y if x1
== x2 or z if x1 == x2 and
y1 ==y2 ?

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Edward A. Falk C Programming 1 04-04-2013 08:07 PM Albert C Programming 18 09-18-2009 07:09 PM subramanian100in@yahoo.com, India C Programming 14 03-11-2007 08:32 PM Spoon C Programming 14 04-18-2006 02:10 PM Debashish Chakravarty C Programming 0 11-23-2003 04:59 AM

Advertisments