?
is zwar keine wirkliche Hilfe, aber versuch doch mal ne
vernünftige Benennung zu finden ..
template<
class Iterator,
class CompareFunctor
>
struct Partition {
Iterator operator()(Iter begin, Iter end, CompareFunctor compare)
{
typedef typename std::iterator_traits<Iter>::value_type Value;
// das ist zwar wirklich unnötig, ich finds irgendwie schöner so ..
Iterator i = begin - 1;
Iterator j = end;
Value pivot = *(end - 1);
while(i < j) {
while(++i != j && compare(*i, pivot) < 0)
;
while(--j != i && compare(pivot, *j) > 0)
;
if(i != j) {
std::iter_swap(i, j);
}
}
std::iter_swap(i, e - 1);
return i;
}
};
template<
class Iterator,
class PartitionFunctor,
class CompareFunctor
>
void quicksort(Iterator begin, Iterator end,
PartitionFunctor partition, CompareFunctor compare)
{
if(end - begin < 2) {
return;
}
Iterator pivot = partition(begin, end, compare);
quicksort(begin, pivot - 1, partition, compare);
quicksort(pivot + 1, end , partition, compare);
}
Übrigens seit wann is es so verdammt 31337 kein using namespace ...; zu
verwenden? Ich kann ja verstehen, wenns heißt man will sich den gobalen
Namespace nicht verschmutzen, aber da gibts doch immer noch die Möglichkeit
ein etwas lokaleres using zu benutzen ...