Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 sort
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Viper




PostPosted: Wed Nov 09, 2005 12:49 pm   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Wed Nov 09, 2005 1:32 pm   Post subject: (No subject)

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]




PostPosted: 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




PostPosted: Wed Nov 09, 2005 6:06 pm   Post subject: (No subject)

code:
#include <cstdlib>


Don't use qsort.
Viper




PostPosted: 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




PostPosted: Thu Nov 10, 2005 2:04 pm   Post subject: (No subject)

It's a C++ wrapper for C's standard library.
[Gandalf]




PostPosted: Thu Nov 10, 2005 4:18 pm   Post subject: (No subject)

wtd wrote:
code:
#include <cstdlib>


Don't use qsort.

Why not? Smile
wtd




PostPosted: 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
Sponsor
sponsor
bugzpodder




PostPosted: 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




PostPosted: 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 Smile
wtd




PostPosted: Wed Nov 16, 2005 5:58 pm   Post subject: (No subject)

The STL sort function is quite fast for most cases.
bugzpodder




PostPosted: 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 Smile


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.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: