From de3e38099609ee8491db2d71b769ca6b00bb5132 Mon Sep 17 00:00:00 2001 From: yashtayade180 <73782668+yashtayade180@users.noreply.github.com> Date: Sun, 3 Oct 2021 21:12:44 +0530 Subject: [PATCH] Update quick_sort.h for better understanding . --- include/quick_sort.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/quick_sort.h b/include/quick_sort.h index b3a74489..94cebad2 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; + int a = begin + 1; + int b = 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]); + while((a <= end) && (list[a] <= pivot)) + a++; + while((b >= begin) && (list[b] > pivot)) + b--; + if(a < b) + 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 } /**