冒泡排序(C++版)

/** Bubble Sort
 *
 * Key
 * * position: where swap
 * * iter: sub-position in each trip
 *
 */     

template <typename T>
void bubble_pos_single(T* a, int n) {
    int pos = n-1;
    while(pos > 0) {
        int iter = 0;
        for(int j = 0; j < pos; j++) {
            if(a[j] > a[j+1]){
                swap(a[j], a[j+1]);
                iter = j;
            }
        }
        pos = iter;
    }
}
原文地址:https://www.cnblogs.com/lifeinsmile/p/5205781.html