Wahoo wrote:

Dear All,

What is the name of sorting algorithm used in list (STL) class? and how it

work?

Thanks!!!

Best Regards,

Wahoo

~ Let us linux ~

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----

http://www.newsfeeds.com - The #1 Newsgroup Service in the World!

-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

std::lists have a sort method, as demonstrated in another reply by Sharad.

In general you can sort any STL container with a random access iterator

using one of the algorithms listed below, declared in <algorithm>.

template<class RandomAccessIterator>

void sort(RandomAccessIterator first, RandomAccessIterator last);

template<class RandomAccessIterator, class Compare>

void sort(RandomAccessIterator first, RandomAccessIterator last,

Compare comp);

template<class RandomAccessIterator>

void stable_sort(RandomAccessIterator first, RandomAccessIterator last);

template<class RandomAccessIterator, class Compare>

void stable_sort(RandomAccessIterator first, RandomAccessIterator last,

Compare comp);

template<class RandomAccessIterator>

void partial_sort(RandomAccessIterator first,

RandomAccessIterator middle,

RandomAccessIterator last);

template<class RandomAccessIterator, class Compare>

void partial_sort(RandomAccessIterator first,

RandomAccessIterator middle,

RandomAccessIterator last,

Compare comp);

template<class InputIterator, class RandomAccessIterator>

RandomAccessIterator

partial_sort_copy(InputIterator first, InputIterator last,

RandomAccessIterator result_first,

RandomAccessIterator result_last);

template<class InputIterator, class RandomAccessIterator,

class Compare>

RandomAccessIterator

partial_sort_copy(InputIterator first, InputIterator last,

RandomAccessIterator result_first,

RandomAccessIterator result_last,

Compare comp);

As an example, consider the following:

#include <iostream>

#include <vector>

#include <iterator>

#include <algorithm>

using namespace std ;

int main()

{

vector<unsigned> v ;

unsigned i ;

for (i = 32; i > 0; i--)

v.push_back(i) ;

sort<vector<unsigned>::iterator>(v.begin(), v.end()) ;

copy(v.begin(), v.end(), ostream_iterator<unsigned>(cout, " ")) ;

cout << endl ;

return 0 ;

}

Alan