黑马程序员技术交流社区
标题:
关于快速排序的一个小例子
[打印本页]
作者:
安静的喝会奶
时间:
2016-6-15 09:31
标题:
关于快速排序的一个小例子
class Test
{
public static void main (String[] args)
{
int[] a = {35,4,59,26,2,63};
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+" ");}
System.out.println();
quicksort(a,0,a.length-1);
for(int i=0;i<a.length;i++){
System.out.print(a[i]+" ");}
}
public static void quicksort( int[] v, int left, int right)
{
if(left < right){
int key = v[left];
int low = left;
int high = right;
while(low < high){
while(low < high && v[high] > key){
high--;
}
v[low] = v[high];
while(low < high && v[low] < key){
low++;
}
v[high] = v[low];
}
v[low] = key;
quicksort(v,left,low-1);
quicksort(v,low+1,right);
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2