System.out.println("hi是从右到左,初始值为:"+hi);
if (lo >=hi) {
System.out.print("lo:"+lo+" hi:"+hi);
System.out.println(" 因为lo:"+lo+">=hi:"+hi+"被返回!!");
return;
}
//确定指针方向的逻辑变量
booleantransfer=true;
while (lo != hi){
System.out.println("lo的值是:"+lo);
System.out.println("hi的值是:"+hi);
if(a[lo] > a[hi]) {
//交换数字
int temp = a[lo];
a[lo] = a[hi];
a[hi] = temp;
System.out.println("交换数字了!"+a[lo]+"和"+a[hi]+"进行了交换,temp的值为:"+temp);
//显示每一次比较的数组数字的变化
System.out.print("现在数组的排列顺序为:");
for(int i = 0; i< a.length; ++i) {
System.out.print(a[i] +",");
}
System.out.println("特殊记号M:"+M);
//决定移动, 是不 ,这个开关是个钟摆,轮流真假两种状态!触发条件是发生交换!
transfer = (transfer == true) false :true;
System.out.println("开关动了,指针要移动了!开关transfer的值为:"+transfer);
}
//将指针向前或者向后移动,默认情况下lo++,注意!有交换不一定会让transfer变为true!--,
if(transfer) {
hi--;
System.out.println("hi被减了1");
}
else{
lo++;
System.out.println("lo被加了1");
}
}
System.out.println("while循环退出,lo和hi相等:"+lo+"="+hi);
//将数组分开两半,确定每个数字的正确位置,return的时候会单独做这个操作
lo--;
hi++;
System.out.println("将数组分开两半,确定每个数字的正确位置,现在lo和hi的值为:"+lo+" "+hi);
System.out.println("M的值为:"+M);
//神奇的M,因为没有传任可值过去,所以M一直为最原先程序所传过来的“0”
System.out.println("quickSort(a, M, lo)");
System.out.println("调用程序之前 M:"+M+" K:"+K+" hi:"+hi+" lo:"+lo );
quickSort(a, M, lo);
System.out.println("调用程序之后 M:"+M+" K:"+K+" hi:"+hi+" lo:"+lo );
System.out.println("quickSort(a, hi, K);");
quickSort(a, hi,K);
System.out.println("调用程序之后 M:"+M+" K:"+K+" hi:"+hi+" lo:"+lo );
}
}
作者:hjm4702192