jacob navia <ja***@jacob.remcomp.frwrites:
rushik wrote:
>I am using structure in my program, and my aim is to sort this
structure based on some optimized sorting algo.
structure is
struct data
{
int account;
int balance;
};
struct data d[200];
I want to sort an array of this structure based on 'balance' (array
can
have multiple entries for same account number), my array size will be
around 150-200 elements.
Can anyone suggest me some optimized sorting algorithm for same.
Use qsort, and write a comparison function that returns -1, 0 or 1
depending on the balance comparison.
qsort() does impose some overhead, since it has to perform an indirect
function call for each comparison. You might get better performance
with a sorting routine that's customized for your type and the kind of
comparison you want to do.
*But* it makes little sense to do this unless you've tried using
qsort(), *measured* its performance, and confirmed that it's a
bottleneck.
If qsort() really isn't fast enough, you could probably adapt an
existing open-source implementation of qsort() to your purposes,
replacing the indirect calls to the comparison function with direct
comparisons.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.