0
我想了解java中的Quicksort算法。Java Quicksort帮助了解
我在旁边的部分我已经评论我的问题,我试图理解。
public class Quciksort {
static void qsort(char items[]) {
qs(items,0,items.length-1); /*how can this method reference its parameters before the method is defined (below)?*/
}
private static void qs(char items[], int left, int right) //
{
int i, j;
char x, y;
i=left; j=right;
x=items[(left+right)/2];
do{
while((items[i] < x) && (i<right)) i++;
while((x < items[j]) && (j>left)) j--;
if(i<=j){
y=items[i];
items[i]=items[j];
items[j]=y;
i++;j--;
}
}while (i<=j);
if(left<j) qs(items, left, j);
if(i<right) qs(items, i, right);
}
}
@Tacocat感谢您的回复,抱歉不会清除。我试图了解如果qs(char items [],int x,int y)直到后面才被创建,qsort()如何调用qs()方法并为其参数赋值? – gencode
@vefthym哦,好吧,我只是假设,因为你不能像> {int r = x + y; int x,y; }你不能对方法做同样的事情。 – gencode
我相信@vefthym已经回答了你的问题,然后〜 – Tacocat