• C

quicksort for a string

I am going to have to quicksort through a list of transaction codes (strings) putting them in ascending order...I want to know how you can do this as the version of the quicksort algorithm that I have sorts only a single string of characters or integers.
fharrisAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dhughes111797Commented:
what OS are you using? I would be surprised if there was
an implementation of quicksort that only worked on a single
string and not an array of <whatever>
The qsort builtin on Solaris and SunOS will do this just fine.
0
rmichelsCommented:
most sorts I have see provide a call back function that allows YOU to do the comparison.  I assume your list of strings is an array of pointers to strings?

I don't have an example of a quick sort though

0
ozoCommented:
You say you want to sort a list of strings, char *list[];
but quicksort only sorts a single string, char *string; ?
I'm confused.  Are you trying to do something like this:

#include <stdlib.h>
#include <string.h>
char *list[]={"transaction2","transaction0","transaction1"};
int cmp(const void *a, const void *b){
  return strcmp(*(char **)a,*(char **)b);
}
qsort(list,sizeof(list)/sizeof(list[0]),sizeof(list[0]),cmp);


0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

alexoCommented:
Some informal testing that I've done showed that radix sort is faster on strings than the standard qsort().

BTW Ozo, you really should start marking your answers as "answer" instead of "comment".  People think that the question is still open.

0
alexoCommented:
Some informal testing that I've done showed that radix sort is faster on strings than the standard qsort().

BTW Ozo, you really should start marking your answers as "answer" instead of "comment".  People think that the question is still open.

0
ozoCommented:
I think the question is still open.
I still don't quite know what the question is.
0
RONSLOWCommented:
sounds to me that 'qsort' is all that required.

What more do you want?

0
hbadrCommented:
what do you want to do by example ?
0
LucHoltkampCommented:
Ozo has an answer, but what do you really want. What datastructure are you using (Linked list, array of char*). The sortingmethode depends on the datastructure.
BTW Please react to our efforts.
.luc.
0
braveheartCommented:
You might like to consider storing the strings in a binary tree, especially if you are going to add (or delete) entries after the initial session.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RONSLOWCommented:
Looks like fharris just ain't listening - or (s)he's listening and not talking.

This sort of attitude doesn't encourage experts to want to help


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.