fharris
asked on
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.
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
I don't have an example of a quick sort though
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","t ransaction 0","transa ction1"};
int cmp(const void *a, const void *b){
return strcmp(*(char **)a,*(char **)b);
}
qsort(list,sizeof(list)/si zeof(list[ 0]),sizeof (list[0]), cmp);
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","t
int cmp(const void *a, const void *b){
return strcmp(*(char **)a,*(char **)b);
}
qsort(list,sizeof(list)/si
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.
BTW Ozo, you really should start marking your answers as "answer" instead of "comment". People think that the question is still open.
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.
BTW Ozo, you really should start marking your answers as "answer" instead of "comment". People think that the question is still open.
I think the question is still open.
I still don't quite know what the question is.
I still don't quite know what the question is.
sounds to me that 'qsort' is all that required.
What more do you want?
What more do you want?
what do you want to do by example ?
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.
BTW Please react to our efforts.
.luc.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
This sort of attitude doesn't encourage experts to want to help
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.