[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


C++ Sorting using Template Functions

Posted on 2005-05-06
Medium Priority
Last Modified: 2010-04-01
Does anyone know of a good web site that has information about how to use different sort methods using Templates?
For example, If wanted to use Quick sort in a template function, like to be able to sort more than just ints or floats, but also variables of custom classes that I create.  I'd like to find this information for other sorts as well like selection sort and insertion sort.  Anyone have any ideas of where I could find information like this?

Question by:hess586
  • 2
LVL 11

Accepted Solution

KurtVon earned 100 total points
ID: 13947681
Well, details on the sort function template that comes with STL can be found here: http://www.sgi.com/tech/stl/sort.html   Supposedly it is a very efficient sort algorithm.  Since the source to STL is available it might still be a good place to start if you have to use a particular algorithm.

If you aren't going to be sorting on iterators it can be a bit more difficult because you need to rely on the underlying structure of the storage object, which means the storage object template itself needs a dedicated sort function.  I believe std::list does this, but I wouldn't swear to it.

Hope this helps.
LVL 14

Expert Comment

ID: 15622356
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:

Split between KurtVon and furqanchandio

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer
LVL 14

Expert Comment

ID: 15625700
Sorry, I didn't realize it was only 25 points.


Accept: KurtVon

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question