#ifndef CA_UWATERLOO_ALUMNI_DWHARDER_BUBBLE_SORT_POINTER #define CA_UWATERLOO_ALUMNI_DWHARDER_BUBBLE_SORT_POINTER namespace Sorting_algorithms { namespace Bubble_sort { class Pointer { public: template static void sort( Type *const array, int const n ) { sort( array, array + n - 1 ); } template static void sort( Type *const lower, Type *upper ) { while ( upper > lower ) { upper = bubble_up( lower, upper ); } } template inline static Type *bubble_up( Type *const lower, Type *const upper ) { Type max = *lower; Type *next = lower; for ( Type *k = lower + 1; k <= upper; ++k ) { if ( *k < max ) { *(k - 1) = *k; next = (k - 1); } else { *(k - 1) = max; max = *k; } } *upper = max; return next; } }; } } #endif