Posted: Wed Nov 09, 2005 4:20 pm Post subject: (No subject)
Is qsort() (quick sort) part of the same library, the math one, or some other?
wtd
Posted: Wed Nov 09, 2005 6:06 pm Post subject: (No subject)
code:
#include <cstdlib>
Don't use qsort.
Viper
Posted: Thu Nov 10, 2005 8:58 am Post subject: (No subject)
what is tht include for?? n thx for the help with the sort
wtd
Posted: Thu Nov 10, 2005 2:04 pm Post subject: (No subject)
It's a C++ wrapper for C's standard library.
[Gandalf]
Posted: Thu Nov 10, 2005 4:18 pm Post subject: (No subject)
wtd wrote:
code:
#include <cstdlib>
Don't use qsort.
Why not?
wtd
Posted: Thu Nov 10, 2005 6:01 pm Post subject: (No subject)
Bedcause qsort resorts to all kinds of void pointer and function pointer madness. The STL's sort function uses templates and operator overloading to accomplish the same thing in a type-safe, convenient way.
Sponsor Sponsor
bugzpodder
Posted: Wed Nov 16, 2005 10:58 am Post subject: (No subject)
qsort is a pain in the ass to use. stick with sort and you'll be fine.
md
Posted: Wed Nov 16, 2005 5:47 pm Post subject: (No subject)
Of course you can always write your own sort function; that way you better understand how it works... and you can customize the sort to your particular needs... a insert sort is faster then a quick sort with mostly sorted data
wtd
Posted: Wed Nov 16, 2005 5:58 pm Post subject: (No subject)
The STL sort function is quite fast for most cases.
bugzpodder
Posted: Mon Nov 28, 2005 10:50 am Post subject: (No subject)
Cornflake wrote:
Of course you can always write your own sort function; that way you better understand how it works... and you can customize the sort to your particular needs... a insert sort is faster then a quick sort with mostly sorted data
that is, assuming quicksort uses the first element as the pivot. I can assure you that any reasonable programmer would use a random pivot or maybe even median of three to implement pivot function in quicksort. in this case, quicksort would perform better. However, it is worthwhile to mention that selection sort (not insertion sort) performs better on smaller datasets (maybe around 20) than quicksort, so a decent quicksort implementation would switch to selection sort when the partition is less than 20. so rest assured that most built-in sorting algorithms are near optimal.