By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,330 Members | 1,523 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,330 IT Pros & Developers. It's quick & easy.

qsort descending order

P: n/a
In the ISO document

http://www.open-std.org/jtc1/sc22/wg...docs/n1124.pdf

in the detail of the qsort library function in 7.20.5.2, the
description says that, the contents of the array are sorted into
ascending order.

MY QUESTION:
Does it mean to include descending order also ?

If not, suppose we write the comparison function in such a way that it
returns less than, equal to, or greater than zero if the first
argument is greater than, equal to, or less than the second argument,
we should be able to use the qsort to sort the array elements into
descending order.

Am I correct or wrong ? Kindly explain.

Mar 19 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
su**************@yahoo.com, India said:
In the ISO document

http://www.open-std.org/jtc1/sc22/wg...docs/n1124.pdf

in the detail of the qsort library function in 7.20.5.2, the
description says that, the contents of the array are sorted into
ascending order.

MY QUESTION:
Does it mean to include descending order also ?
No. You define what "ascending" means in your comparison function, by
the way in which you associate the return value of the function with
the result of the comparison.
If not, suppose we write the comparison function in such a way that it
returns less than, equal to, or greater than zero if the first
argument is greater than, equal to, or less than the second argument,
we should be able to use the qsort to sort the array elements into
descending order.
Right.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 19 '07 #2

P: n/a
<su**************@yahoo.comwrote:
In the ISO document

http://www.open-std.org/jtc1/sc22/wg...docs/n1124.pdf

in the detail of the qsort library function in 7.20.5.2, the
description says that, the contents of the array are sorted into
ascending order.

MY QUESTION:
Does it mean to include descending order also ?

If not, suppose we write the comparison function in such a way that it
returns less than, equal to, or greater than zero if the first
argument is greater than, equal to, or less than the second argument,
we should be able to use the qsort to sort the array elements into
descending order.

Am I correct or wrong ? Kindly explain.
I think the word "ascending" should not have been used in the specification.
Mar 19 '07 #3

P: n/a
"osmium" <r1********@comcast.netwrote:
<su**************@yahoo.comwrote:
In the ISO document

http://www.open-std.org/jtc1/sc22/wg...docs/n1124.pdf

in the detail of the qsort library function in 7.20.5.2, the
description says that, the contents of the array are sorted into
ascending order.

MY QUESTION:
Does it mean to include descending order also ?

If not, suppose we write the comparison function in such a way that it
returns less than, equal to, or greater than zero if the first
argument is greater than, equal to, or less than the second argument,
we should be able to use the qsort to sort the array elements into
descending order.

Am I correct or wrong ? Kindly explain.

I think the word "ascending" should not have been used in the specification.
Why not? qsort() sorts the array in ascending order, with respect to the
comparison function supplied. This can be ascending /qua/ numerical
size, ascending /qua/ age struct member, or ascending /qua/ _inverse_ of
the number of spots.

Richard

Richard
Mar 19 '07 #4

P: n/a
In article <45****************@news.xs4all.nl>,
Richard Bos <rl*@hoekstra-uitgeverij.nlwrote:
>I think the word "ascending" should not have been used in the
specification.
>Why not?
Because, apparently, it is confusing. Of course you can say that
3,2,1 are in ascending order with respect to a comparison function
that says 1>2>3, but is it the clearest way to do it? The only problem
is finding a better terminology - perhaps the terms "earlier" and
"later" could have been used?

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Mar 19 '07 #5

P: n/a
"su**************@yahoo.com, India" wrote:
>
In the ISO document

http://www.open-std.org/jtc1/sc22/wg...docs/n1124.pdf

in the detail of the qsort library function in 7.20.5.2, the
description says that, the contents of the array are sorted into
ascending order.

MY QUESTION:
Does it mean to include descending order also ?

If not, suppose we write the comparison function in such a way that it
returns less than, equal to, or greater than zero if the first
argument is greater than, equal to, or less than the second argument,
we should be able to use the qsort to sort the array elements into
descending order.

Am I correct or wrong ? Kindly explain.
The only thing that defines order is the comparison function. So
you are correct.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews

--
Posted via a free Usenet account from http://www.teranews.com

Mar 20 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.