
-----------------------------------
Viper
Wed Nov 09, 2005 12:49 pm

sort
-----------------------------------
i had heard there was a build in sorter in DevC++ is this true?? if so could someone show me how to use it plz n thx

-----------------------------------
wtd
Wed Nov 09, 2005 1:32 pm


-----------------------------------
Dev-C++ is an environment for writing C++ code, not a language.

C++'s Standard Template Library does have a "sort" function.

http://www.fredosaurus.com/notes-cpp/algorithms/sorting/stl-sort-arrays.html

-----------------------------------
[Gandalf]
Wed Nov 09, 2005 4:20 pm


-----------------------------------
Is qsort() (quick sort) part of the same library, the math one, or some other?

-----------------------------------
wtd
Wed Nov 09, 2005 6:06 pm


-----------------------------------
#include 

Don't use qsort.

-----------------------------------
Viper
Thu Nov 10, 2005 8:58 am


-----------------------------------
what is tht include for?? n thx for the help with the sort

-----------------------------------
wtd
Thu Nov 10, 2005 2:04 pm


-----------------------------------
It's a C++ wrapper for C's standard library.

-----------------------------------
[Gandalf]
Thu Nov 10, 2005 4:18 pm


-----------------------------------
#include 

Don't use qsort.
Why not? :)

-----------------------------------
wtd
Thu Nov 10, 2005 6:01 pm


-----------------------------------
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.

-----------------------------------
bugzpodder
Wed Nov 16, 2005 10:58 am


-----------------------------------
qsort is a pain in the ass to use.  stick with sort and you'll be fine.

-----------------------------------
md
Wed Nov 16, 2005 5:47 pm


-----------------------------------
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
Wed Nov 16, 2005 5:58 pm


-----------------------------------
The STL sort function is quite fast for most cases.

-----------------------------------
bugzpodder
Mon Nov 28, 2005 10:50 am


-----------------------------------
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.
