Algorithm:CustomSorts

From GPWiki
Jump to: navigation, search
template <typename iter> 
void selection_sort(iter b, iter e) {
    for( ; b != e; ++b ) {
        iter_swap( b, min_element(b,e) );
    }
}
template <typename iter> 
void recursive_selection_sort(iter b, iter e) {
    if ( b == e ) return;
    iter_swap( b, min_element(b,e) );
    recursive_selection_sort( ++b, e );
}
template <typename iter>
void insertion_sort(iter b, iter e) {
    for( iter o = b; o++ != e; ) {
        rotate( upper_bound( b, o, *(o-1) ), o-1, o );
    }
}