ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I would use a merge sort or a quick sort personally, but performance is highly dependant on how the data happens to fall.
I've found in real world performance the bubble sort rarely, if ever, will touch the performance of merge sort or quick sort, though I'm sure with some specifically structured datasets we could show bubble sort to be quite fast.
Your best solution:
try a known C library function like qsort, first. You are less likely to have problems later on. qsort has been beat on for 15+ years. Most of the problems have long since been chased out.
Test it on real data, not programmer data. If it works okay, don't worry about squeezing an extra five seconds off run-time. It is not worth your time.
If you are in a big production environment, look for commercial libraries like syncsort. Don't try to write a linear time sort on your own.
IE. Theres 20 numbers and the first 15 are sorted but the remaining 5 are still jumbled.
In reality it might be the first 99% of them are sorted, or something like that. I'm not in a big production enviornment, so I can't afford commercial licences.