#ifndef CA_UWATERLOO_ALUMNI_DWHARDER_INSERTION_SORT_BASIC #define CA_UWATERLOO_ALUMNI_DWHARDER_INSERTION_SORT_BASIC namespace Sorting_algorithms { namespace Insertion_sort { class Basic { public: template static void sort( Type *array, int n ) { for ( int i = 1; i < n; ++i ) { for ( int j = i - 1; j >= 0; --j ) { if ( array[j] > array[j + 1] ) { swap( array, j, j + 1 ); } else { break; } } } } template void insertion_sort( Type *array, int a, int b ) { insertion_sort( array + a, b - a + 1 ); } private: template static void swap( Type *array, int i, int j ) { Type tmp = array[i]; array[i] = array[j]; array[j] = tmp; } }; } } #endif