哎,还是靠断点慢慢给调试出来了。。。。。
package test;
public class QuickSort {
int[] arr={49,38,65,97,10,40,87,76,13,27};
public void sort(int start,int end,int key)
{
if(start>=(arr.length-1) || end<=0)
return;
if(start==end)
{
int left1=0;
int right1=start-1;
int newkey1=arr[left1];
sort(left1,right1,newkey1);
int left2=start+1;
int right2=arr.length-1;
int newkey2=arr[left2];
sort(left2,right2,newkey2);
return;
}
while(arr[end]>key && start<end)
end--;
while(arr[start]<key && start<end)
start++;
int temp=arr[start];
arr[start]=arr[end];
arr[end]=temp;
sort(start,end,key);
}
public void sortAll(int start,int end,int key)
{
sort(start,end,key);
for(int i:arr)
System.out.print(i+" ");
}
public static void main(String[] args)
{
QuickSort qs=new QuickSort();
qs.sortAll(0, qs.arr.length-1,qs.arr[0]);
}
}
本文通过逐步调试的方式详细解析了快速排序算法的具体实现过程。针对一个整数数组,作者运用递归思想,通过选取基准元素并调整数组左右两侧元素的位置来实现排序。文章展示了具体的调试步骤,有助于读者深入理解快速排序的工作原理。

被折叠的 条评论
为什么被折叠?



