noop comparator for qsort

From: Trent Buck (NOSPAMfubarbaz_at_bigpond.com)
Date: 11/14/04


Date: Sun, 14 Nov 2004 08:15:15 GMT

The fourth argument is a comparator that returns `an integer less than,
equal to, or greater than zero' depending on the ordering of its
arguments.

If I don't care about the order and simply want qsort() to run as
quickly as possible, how should the comparator be defined?

If qsort were stable, the following would be best:

        int
        compare (void *x, void *y)
        {
          return 0;
        }

...is this still true for a possibly non-stable qsort()?

-trent



Relevant Pages

  • Re: noop comparator for qsort
    ... >The fourth argument is a comparator that returns `an integer less than, ... or greater than zero' depending on the ordering of its ... If you want it to run quickly, don't call qsort() at all. ... provide a good ordering of the elements, requiring among ...
    (comp.lang.c)
  • Re: noop comparator for qsort
    ... >> The fourth argument is a comparator that returns `an integer less than, ... or greater than zero' depending on the ordering of its ... >> If I don't care about the order and simply want qsort() to run as ... > How about comparing the pointers rather than the items pointed to? ...
    (comp.lang.c)
  • Re: noop comparator for qsort
    ... Baffling remark!! ... how should the comparator be defined? ... This would be great, if you wanted qsort() to do nothing, possibly taking ... CLC FAQ CLC readme: ...
    (comp.lang.c)
  • Re: About quicksort procedure in icon
    ... for the comparator class) showing how qsort can be used. ... Note that lists of much more complicated items can can ...
    (comp.lang.icon)
  • Re: noop comparator for qsort
    ... Baffling remark!! ... >>and simply want qsort() to run as ... how should the comparator be defined? ... perfectly reasonable comperator. ...
    (comp.lang.c)