バブルソート(C++版)
1557 ワード
/** 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;
}
}