中级农民
- 积分
- 232
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2010-6-11
- 最后登录
- 1970-1-1
|
public static void swap (int A[], int x, int y)
{
int temp = A[x];
A[x] = A[y];
A[y] = temp;
}
// Reorganizes the given list so all elements less than the first are
// before it and all greater elements are after it.
public static int partition(int A[], int f, int l)
{
int pivot = A[f];
while (f < l)
{
if (A[f] == pivot || A[l] == pivot)
{
System.out.println("Only distinct integers allowed - C321");
System.out.println("students should ignore this if statement");
System.out.exit(0);
}
while (A[f] < pivot) f++;
while (A[l] > pivot) l--;
swap (A, f, l);
}
return f;
}
public static void Quicksort(int A[], int f, int l)
{
if (f >= l) return;
int pivot_index = partition(A, f, l);
Quicksort(A, f, pivot_index);
Quicksort(A, pivot_index+1, l);
}
|
|