Solved

quicksort for a string

Posted on 1997-12-10
11
1,192 Views
Last Modified: 2012-08-14
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.
0
Comment
Question by:fharris
  • 2
  • 2
  • 2
  • +5
11 Comments
 
LVL 1

Expert Comment

by:dhughes111797
Comment Utility
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
 
LVL 3

Expert Comment

by:rmichels
Comment Utility
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
 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
 
LVL 11

Expert Comment

by:alexo
Comment Utility
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
 
LVL 11

Expert Comment

by:alexo
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 84

Expert Comment

by:ozo
Comment Utility
I think the question is still open.
I still don't quite know what the question is.
0
 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
sounds to me that 'qsort' is all that required.

What more do you want?

0
 

Expert Comment

by:hbadr
Comment Utility
what do you want to do by example ?
0
 
LVL 3

Expert Comment

by:LucHoltkamp
Comment Utility
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
 
LVL 3

Accepted Solution

by:
braveheart earned 100 total points
Comment Utility
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
 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now