BUG: qsort reorders elements in already sorted array
Corinna Vinschen
vinschen@redhat.com
Wed Jun 4 19:13:00 GMT 2003
On Wed, Jun 04, 2003 at 01:49:18PM -0400, James Roth wrote:
> It sounds like you want to sort by more than one key. Why not have
> your compare function actually do that. This way, the undefined qsort
> results are not relevant.
>
> struct info
> {
> int score;
> int date; /* or article number, etc. */
> };
>
> int
> compare (void *v1, void *v2)
> {
> struct info *i1 = v1, *i2 = v2;
>
> if (v1->score - v2->score) /* Maybe you want v2 - v1 */
> return v1->score - v2->score; /* Scores are different, so ignore
> date. */
> else
> return v1->date - v2->date; /* Scores are same, so use date. */
> }
That seems to be a good idea to suggest to the tin ML, I guess.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Developer
Red Hat, Inc.
mailto:vinschen@redhat.com
More information about the Newlib
mailing list