Re: qsort() results: implementation dependent?
- From: "Max" <iprmaster@xxxxxxxxx>
- Date: 28 Jun 2006 05:26:30 -0700
Duncan Muirhead schrieb:
I'm not sure if this is specified for qsort but I've learnt not to use
it unless the compare function really is an order, ie unless the compare
function only returns 0 if the two arguments are identical.
You are right, but how to accomplish with that if you are dealing with
doubles? Such a routine is expected to order points belonging to two
different surfaces which are related by a geometrical transformation
(translation or rotation). Ordering them according to the distance from
the origin should store the pairs in sequence and make simple to split
the resulting ordered list in two vector. If you know other (cheap?)
algorithms, I will try them...
Otherwise, in
may experience at least, qsort can fail spectacularly (cause a core dump),
and anyway I'd suspect that if it returns the final order of the array,
(ie the order of the elements that are all equal as fare as the compare is
concerned) is not just implementation but phase-of-the-moon dependent if
the compare can return non zero for two different arguments
Could you perhaps extend your comparison, function, eg if two points
are the same distance from the origin, compare x then y
then z coordinates too?
Duncan
You are right and it is what the real code does. I gave an simpler
example (already tried) to focus on the topic.
Thanks
Max
.
- Follow-Ups:
- Re: qsort() results: implementation dependent?
- From: Eric Sosman
- Re: qsort() results: implementation dependent?
- From: pete
- Re: qsort() results: implementation dependent?
- References:
- qsort() results: implementation dependent?
- From: Max
- Re: qsort() results: implementation dependent?
- From: Duncan Muirhead
- qsort() results: implementation dependent?
- Prev by Date: Re: Constructor equivalent
- Next by Date: Re: linux redirect problem
- Previous by thread: Re: qsort() results: implementation dependent?
- Next by thread: Re: qsort() results: implementation dependent?
- Index(es):
Relevant Pages
|