成都网站建设设计

将想法与焦点和您一起共享

java排序算法的代码 java排序算法实现

关于JAVA快速排序算法问题,请大神指教啊!!!

//我按着你的思路写的,自己看看吧,睁橡郑链我运行过,结果正确

松桃网站建设公司成都创新互联,松桃网站设计制作,有大型网站制作公司丰富经验。已为松桃近1000家提供企业网站建设服务。企业网站搭建\外贸网站建设要多少钱,请找那个售后服务好的松桃做网站的公司定做!

public class QuickSort {

public static void main(String[] args) {

int[] array = new int[]{2,5,3,8,7,0,1,4,6,9,10};

int left = 0;

int right = array.length-1;

qsort(array,left,right);

for(int index:array){

System.out.print(index+" ");

}

}

public static void qsort(int[] array,int left,int right){

int p;

if(left悉丛旁right){

p = partition(array,left,right);

qsort(array,left,p-1);

qsort(array,p+1,right);

}

}

public static int partition(int[] arr,int left,int right){

int temp_val;

int temp_r, temp_l, temp_m;

temp_r = right;

temp_l = left;

temp_m = left;

boolean flag = true;

while(temp_l temp_r){

if(flag){

if(arr[temp_m] arr[temp_r]){

temp_val = arr[temp_m];

arr[temp_m] = arr[temp_r];

arr[temp_r] = temp_val;

temp_m = temp_r;

flag = false;

}

temp_r --;

}else{

if(arr[temp_m] arr[temp_l]){

temp_val = arr[temp_m];

arr[temp_m] = arr[temp_l];

arr[temp_l] = temp_val;

temp_m = temp_l;

flag = true;

}

temp_l ++;

}

}

return temp_m;

}

}


网站名称:java排序算法的代码 java排序算法实现
本文URL:http://chengdu.cdxwcx.cn/article/dsppgdo.html