what is the best / fastest way to sort strings alphabetically or numerically?
what is the best / fastest way to sort strings alphabetically or numerically?
Qsort.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Merge sort can be faster depending on the data given...
ve a look here
QuickSort
i am having trouble implementing quicksort... i cannot find decent implementation details... I'm still pretty green when it comes to programming, so anything in plain english would be most helpful.
Last edited by criticalerror; 03-04-2004 at 09:44 AM.
actually, a variation on RADIX applied to strings instead of integers would be much faster than qsort or merge sort.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
>what is the best / fastest way to sort strings alphabetically or numerically?
>I'm still pretty green when it comes to programming
The best way would be to use the build-in sort function given to you by the standard library:
If you have trouble implementing a basic quicksort then why try to use a faster (and more complex) specialized sort? Chances are very good that the general sort function will be more than fast enough.Code:#include <iostream> #include <algorithm> #include <string> using namespace std; void print ( const string& s ) { cout<< s <<endl; } int main() { string list[] = { "This", "is", "a", "test", "of", "C++'s", "string", "sorting", "capability" }; sort ( list, list + 9 ); for_each ( list, list + 9, print ); }
My best code is written with the delete key.
it also depends on what you're using it for. If you're trying to store them in a way you can get to them quickly, look up suffox trie (sp?) or hash tables should do the trick. When it comes to finding a string in a list I prefer suffox tries because they are blazing fast.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
>When it comes to finding a string in a list I prefer suffox tries because they are blazing fast.
The OP has trouble with quicksort and you suggest using a suffix trie? Have fun explaining how one works and helping with the code.
My best code is written with the delete key.
Prelude, he asked what the fastest way was, not which way he or she should use. But you're right of course.
edit:
Plus, I haven't really been here the last couple months. I think I'm aloud to be a little bit odd on my return
Last edited by FillYourBrain; 03-04-2004 at 02:34 PM.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
>he asked what the fastest way was, not which way he or she should use
Actually, he asked for the best/fastest way. The 'best' part gives us a little leway in suggesting what's best for him instead of best in general.
>I think I'm aloud to be a little bit odd on my return
That works for me.
My best code is written with the delete key.
thanks guys!