C++ Sorting using Template Functions

Posted on 2005-05-06
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
    LVL 11

    Accepted Solution

    Well, details on the sort function template that comes with STL can be found here:   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 4

    Expert Comment

    LVL 14

    Expert Comment

    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

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


    Accept: KurtVon

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
      Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    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…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now