Hello fellow programmers, 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; } } Edit: I tried an iterator approach using the modern C++ way as suggested: <br> Could someone tell me if there are mistakes since I am not used to this approach. template<typename Iterator, typename Comparator> void selection_sort(Iterator begin, Iterator end, Comparator comparator) { for (; begin != end; ++begin) { auto min = std::min_element(begin, end, comparator); if (comparator(*min, *begin)) { std::iter_swap(min, begin); } } } template<typename Iterator> void selection_sort(Iterator begin, Iterator end) { typedef typename std::iterator_traits<Iterator>::value_type value_type; selection_sort(begin, end, std::less<value_type>()); }