I was wondering if this implementation of insertion sort could be improved. Are there any things that I have done wrong?
template<typename Element>
void insertion_sort(Element arr[], size_t size) {
size_t index, index_sorted;
for (index = 0u; index < size; ++index) {
auto temp = arr[index];
index_sorted = index - 1;
while (arr[index_sorted] >= 0 && arr[index_sorted] > temp) {
arr[index_sorted + 1] = arr[index_sorted--];
}
arr[index_sorted + 1] = temp;
}
}
arr[index_sorted + 1] = arr[index_sorted--];
is undefined behavior. More info \$\endgroup\$