Skip to content

Commit b023507

Browse files
authored
Update quicksort.cpp
1 parent 99702a8 commit b023507

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Algorithm/quicksort.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void quicksort(T* arr, int start, int end)
88
int i = start + 1, j = end, pivot = arr[start]; //轴值的选择多种多样,最稳当的方式是三点中值法(Median-of-Three),这里简单的选择数组第一个值arr[start]为轴值
99
while (i < j)
1010
{
11-
while (j != 0 && arr[j] > pivot) j--;
11+
while (j != i && arr[j] > pivot) j--;
1212
while (i != j && arr[i] < pivot) i++;
1313
if (i < j)
1414
std::swap(arr[i++], arr[j--]);
@@ -28,4 +28,4 @@ int main(int argc, char const *argv[])
2828
std::cout << i << " ";
2929
}
3030
return 0;
31-
}
31+
}

0 commit comments

Comments
 (0)