473,228 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

required algorithm for sorting a structure

Hello all,

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.

Thanks,
Rushik.

Oct 3 '06 #1
4 2134
rushik wrote:
Hello all,

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.

Thanks,
Rushik.
Use qsort, and write a comparison function that returns -1, 0 or 1
depending on the balance comparison.
Oct 3 '06 #2
rushik wrote:
Hello all,

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.
For a mere 200 elements, why do you want an "optimised" sorting
algorithm?

Use `qsort` unless you have a reason not to.

--
Chris "falling further in" Dollin
"It took a very long time, much longer than the most generous estimates."
-James White, /Sector General/

Oct 3 '06 #3
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.
Oct 3 '06 #4

Chris Dollin wrote:
rushik wrote:
Hello all,

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.

For a mere 200 elements, why do you want an "optimised" sorting
algorithm?

Use `qsort` unless you have a reason not to.

--
Chris "falling further in" Dollin
"It took a very long time, much longer than the most generous estimates."
-James White, /Sector General/
Thanks for suggestions......I will be using qsort... my array will be
having at max 2500 structure elements.

Rushik.

Oct 4 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Shaunak Kashyap | last post by:
Does anyone know what sorting algorithm(s) -- quicksort, mergesort, radix sort, etc. -- does PHP use internally in its sort function?
16
by: cody | last post by:
I have to write an algorithm with must ensure that objects are put in buckets (which are always 4 in size). The objects have two properties: A and B. It is not allowed that in a bucket are objects...
2
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
11
by: rkbnair | last post by:
I have created a datagrid in my aspx with the 'AllowSorting' property to true. When clicking on the column header, the page refreshes. However the sorting is not done. Am I missing anything? I...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
5
by: chrisguest | last post by:
I am trying to write some code that will take a list of functional expressions, and order them so that those with primitive terms appear at the beginning of the list and those that are defined by...
51
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort...
0
by: JosAH | last post by:
Greetings, I was asked to write a Tip Of the Week; so here goes: a lot of topics are started here in this forum (and a lot of other forums too) mentioning a problem about sorting data. ...
1
Ganon11
by: Ganon11 | last post by:
Hey guys, I'm back, and with another FUN question! My latest homework asks this question: "Suppose all the edge weights in a graph are integers between 1 and |E|. How fast can Dijkstra's...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.