#ifndef CA_UWATERLOO_ALUMNI_DWHARDER_SELECTION_SORT_ARRAY #define CA_UWATERLOO_ALUMNI_DWHARDER_SELECTION_SORT_ARRAY namespace Sorting_algorithms { namespace Selection_sort { class Array { public: template static void sort( Type *const array, int const n ) { sort( array, 0, n - 1 ); } template static void sort( Type *const array, int const a, int const b ) { for ( int i = a; i <= b; ++i ) { Type min = array[i]; int posn = i; for ( int j = i + 1; j <= b; ++j ) { if ( array[j] < min ) { min = array[j]; posn = j; } } swap( array, i, posn ); } } private: template inline static void swap( Type *const array, int i, int j ) { Type tmp = array[i]; array[i] = array[j]; array[j] = tmp; } }; } } #endif