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 RandomAccessIte rator>
void sort(RandomAcce ssIterator first, RandomAccessIte rator last);
template<class RandomAccessIte rator, class Compare>
void sort(RandomAcce ssIterator first, RandomAccessIte rator last,
Compare comp);
template<class RandomAccessIte rator>
void stable_sort(Ran domAccessIterat or first, RandomAccessIte rator last);
template<class RandomAccessIte rator, class Compare>
void stable_sort(Ran domAccessIterat or first, RandomAccessIte rator last,
Compare comp);
template<class RandomAccessIte rator>
void partial_sort(Ra ndomAccessItera tor first,
RandomAccessIte rator middle,
RandomAccessIte rator last);
template<class RandomAccessIte rator, class Compare>
void partial_sort(Ra ndomAccessItera tor first,
RandomAccessIte rator middle,
RandomAccessIte rator last,
Compare comp);
template<class InputIterator, class RandomAccessIte rator>
RandomAccessIte rator
partial_sort_co py(InputIterato r first, InputIterator last,
RandomAccessIte rator result_first,
RandomAccessIte rator result_last);
template<class InputIterator, class RandomAccessIte rator,
class Compare>
RandomAccessIte rator
partial_sort_co py(InputIterato r first, InputIterator last,
RandomAccessIte rator result_first,
RandomAccessIte rator 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<uns igned>::iterato r>(v.begin(), v.end()) ;
copy(v.begin(), v.end(), ostream_iterato r<unsigned>(cou t, " ")) ;
cout << endl ;
return 0 ;
}
Alan