diff --git a/include/quick_sort.h b/include/quick_sort.h index b3a74489..020369a6 100644 --- a/include/quick_sort.h +++ b/include/quick_sort.h @@ -30,20 +30,20 @@ namespace alg { T pivot = list[pivot_idx]; swap(list[begin], list[pivot_idx]); - int i = begin + 1; - int j = end; - - while(i <= j) { - while((i <= end) && (list[i] <= pivot)) - i++; - while((j >= begin) && (list[j] > pivot)) - j--; - if(i < j) - swap(list[i],list[j]); + int a = begin + 1; + int b = end; + + while(a <= b) { + while((a <= end) && (list[a] <= pivot)) + a++; + while((b >= begin) && (list[b] > pivot)) + b--; + if(a < ) + swap(list[a],list[b]); } - swap(list[begin],list[j]); - return j; // final pivot position + swap(list[begin],list[b]); + return b; // final pivot position } /**