Skip to content
Permalink
Browse files

修复快排在给定数组所有元素均相同的情况下的问题

  • Loading branch information...
panjf2000 committed Mar 10, 2019
1 parent f366f72 commit 0171bd30b7136f6579a3c24352d4f3bd412b4e4f
Showing with 4 additions and 3 deletions.
  1. +1 −1 排序算法/QuickSort.java
  2. +1 −1 排序算法/qsort.cpp
  3. +2 −1 排序算法/qsort.go
@@ -13,7 +13,7 @@ public int partition(int[] a, int i, int j) {
int b = i, e = j + 1;
int x = a[i];
while (true) {
while (b < j && a[++b] < x)
while (b < j && a[++b] <= x)
;
while (a[--e] > x)
;
@@ -18,7 +18,7 @@ int Partition(Type a[], int p, int r)
Type x = a[p];
while (true)
{
while (a[++i] < x && i < r);
while (a[++i] <= x && i < r);
while (a[--j] > x);
if (i >= j)
break;
@@ -8,7 +8,7 @@ func partition(a []int, left, right int) int {
low, up := left+1, right
x := a[left]
for {
for a[low] < x && low < up {
for a[low] <= x && low < up {
low++
}
for a[up] > x {
@@ -20,6 +20,7 @@ func partition(a []int, left, right int) int {
a[low], a[up] = a[up], a[low]
}
a[left], a[up] = a[up], a[left]
fmt.Println(a, up)
return up
}

0 comments on commit 0171bd3

Please sign in to comment.
You can’t perform that action at this time.