Why would you do that? Just use std::sort. There is a version of it that takes a functor or predicate and it works for c-arrays and std sequence containers and it will be more efficient than a bubble sort.
kempofighter (1070) Dec 15, 2010 at 11:25pm
Why would you do that? Just use std::sort. There is a version of it that takes a functor or predicate and it works for c-arrays and std sequence containers and it will be more efficient than a bubble sort.
template<class Iter, class functor>
void sorts(Iter beg, Iter end, functor f)
{
int size = end - beg;
for (int k = 0; k < size -1; k++){
for (int i = 0; i < size -1 -k; i++)
if (f(beg[i], beg[i + 1]))
swap(beg[i],beg[i + 1]);
}
}