Bubblesort is easy enough to implement even if it is not the most performant:
- Fill the array with all the pointers.
- loop until all sorted
- loop from first element and swap with next if their order is wrong until the sorted elements are reached (at that point the end element is highest, thus sorted)
Remark that for all other than educational purposes (or possible optimization), std::sort should be preferred over own implementations.
A comment stated that bubblesort is complex and difficult, so I added an implementation of the algorithm in my answer. Mind you that especially the end-condition of the inner loop (j < i - 1) must be correct and that the direction of the outer and inner loop must be opposite. And it can be optimised by stopping if no swap was done, but we weren't concerned with performance in the first place.
template <typename T>
void bubbleSort(T* arr, int nbr, bool(*comp)(const T& left, const T& right))
{
for (int i = nbr; i > 1; --i)
{
for (int j = 0; j < i-1; ++j)
{
if (!comp(arr[j], arr[j+1])) std::swap(arr[j], arr[j+1]);
}
}
}