I was wondering if this implementation of selection sort could be improved. Are there any things that I have done wrong?
template<typename Element>
void selection_sort(Element arr[], size_t size) {
auto index_toSort = 0u;
while (index_toSort < size) {
auto index_smallest = index_toSort;
for (auto index = index_toSort; index < size; ++index) {
if (arr[index] < arr[index_smallest]) {
index_smallest = index;
}
}
std::swap(arr[index_toSort], arr[index_smallest]);
++index_toSort;
}
}
index_toSort
toindex_to_sort
for consistency/personal aesthetics). Of course, one could always generalize for different ordering and/or iterators, but those aspects seem out of scope for your sort implementations (at least to me). \$\endgroup\$