#include #include #include #include using namespace std; struct Ascending { template static bool less(T const & lhs, T const & rhs) { return lhs < rhs; } }; struct Descending { template static bool less(T const & lhs, T const & rhs) { return lhs != rhs && rhs < lhs; } }; template struct Sort { template static void sort(Iter begin, Iter end) { for ( ; next(begin) != end; ++begin) { Iter min = begin; for (Iter pos = next(begin); pos != end; ++pos) if ( Order_Policy::less(*pos, *min) ) min = pos; std::iter_swap(begin, min); } } }; // a general print function to see that the sorting works. // This was not required. template void print(Cont const & arr) { bool first {true}; for ( auto i : arr ) { if ( !first ) cout << ", "; first = false; cout << i; } cout << endl; } int main() { int arr[] = {2,3,5,1,6,8}; Sort::sort(begin(arr), end(arr)); print(arr); vector values {2,3,6,8,3}; Sort::sort(begin(values), end(values)); print(values); list words {"hi", "hello", "all", "students"}; Sort::sort(begin(words), end(words)); print(words); }