public static int findPartition(int A[], int i, int j)
{
int val = A[i];
while (i >= 0 && i < j && j >= 0)
{
System.out.println("in find partition");
System.out.println("i : " + i);
System.out.println("j : " + j);
while (A[j] > val)
{
j--;
}
if (i < j && A[j] <= val)
{
exchange(A, j, i);
}
while (A[i] < val)
{
i++;
}
if (i < j && A[i] >= val)
{
exchange(A, i, j);
}
}
return j;
}
public static void sort(int A[], int start, int end)
{
if (start <= end)
{
int pos = findPartition(A, start, end);
sort(A, start, pos - 1);
sort(A, pos + 1, end);
}
}
Quick Sort
最新推荐文章于 2025-05-20 09:34:15 发布