Skip to content

Commit 93dccc0

Browse files
committed
修改快速排序
1 parent 722da5d commit 93dccc0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • src/main/java/cn/byhieg/algorithmtutorial

src/main/java/cn/byhieg/algorithmtutorial/Sort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ public int partition(int[] nums, int low, int high) {
165165
int x = nums[i];
166166
while (i < j) {
167167
//从右向左找到nums[j]小于x的元素
168-
while (i < j && nums[j] > x) j--;
168+
while (i < j && nums[j] >= x) j--;
169169
if (i < j) {
170170
nums[i] = nums[j];
171171
i++;
172172
}
173173

174174
//从左向右找到nums[i]大于x的元素
175-
while (i < j && nums[i] < x) i++;
175+
while (i < j && nums[i] <= x) i++;
176176
if (i < j) {
177177
nums[j] = nums[i];
178178
j--;

0 commit comments

Comments
 (0)