Quicksort / vector / partition issue
Posted
by xxx
on Stack Overflow
See other posts from Stack Overflow
or by xxx
Published on 2010-05-26T13:30:35Z
Indexed on
2010/05/26
13:31 UTC
Read the original article
Hit count: 268
Hi,
I have an issue with the following code :
class quicksort {
private:
void _sort(double_it begin, double_it end)
{
if ( begin == end ) { return ; }
double_it it = partition(begin, end, bind2nd(less<double>(), *begin)) ;
iter_swap(begin, it-1);
_sort(begin, it-1);
_sort(it, end);
}
public:
quicksort (){}
void operator()(vector<double> & data)
{
double_it begin = data.begin();
double_it end = data.end() ;
_sort(begin, end);
}
};
However, this won't work for too large a number of elements (it works with 10 000 elements, but not with 100 000).
Example code :
int main()
{
vector<double>v ;
for(int i = n-1; i >= 0 ; --i)
v.push_back(rand());
quicksort f;
f(v);
return 0;
}
Doesn't the STL partition function works for such sizes ? Or am I missing something ?
Many thanks for your help.
© Stack Overflow or respective owner