java的快速排序

写了2个形式的,原理差不多,都是找基数,递归到一个结束。但是细节和交换上有所不同。

相关code

package day20180728;

public class QuickSort{
    
    public static void quickSort(int[] arr,int lt,int rt)
    {
    //只有一个元素的时候,递归出口
        if(lt>=rt)
            return;
        
       int temp=arr[lt];
       int st=lt,end=rt;
       
       while(st=arr[st])
           {
               st++;
           }
           
           if(st

结果

每一次左右轮换的结果为
11 6 8 0 33 78 65 22 
#########
每一次左右轮换的结果为
11 6 8 0 33 78 65 22 
#########
基数为:3
基数定位的结果为:
------****-------
0 6 8 11 33 78 65 22 ++++++++++
每一次左右轮换的结果为
0 6 8 11 33 78 65 22 
#########
基数为:0
基数定位的结果为:
------****-------
0 6 8 11 33 78 65 22 ++++++++++
每一次左右轮换的结果为
0 6 8 11 33 78 65 22 
#########
基数为:1
基数定位的结果为:
------****-------
0 6 8 11 33 78 65 22 ++++++++++
每一次左右轮换的结果为
0 6 8 11 33 22 65 78 
#########
每一次左右轮换的结果为
0 6 8 11 33 22 65 78 
#########
基数为:5
基数定位的结果为:
------****-------
0 6 8 11 22 33 65 78 ++++++++++
每一次左右轮换的结果为
0 6 8 11 22 33 65 78 
#########
基数为:6
基数定位的结果为:
------****-------
0 6 8 11 22 33 65 78 ++++++++++
0 6 8 11 22 33 65 78 

另外一个版本
code如下

package day20180728;

public class qSort {
    
    
    public static void ksort(int[] arr,int left,int right)
    {
        if(left>=right)
            return ;
        int tag=arr[left];
        int i=left,j=right;
        
        while(i=arr[i])
            {
                i++;
            }
            
            if(i

结果

基数i为:2
基数定位的结果为:
------////-------
0 8 11 22 33 78 65 66 /////////////
基数i为:0
基数定位的结果为:
------////-------
0 8 11 22 33 78 65 66 /////////////
基数i为:3
基数定位的结果为:
------////-------
0 8 11 22 33 78 65 66 /////////////
基数i为:4
基数定位的结果为:
------////-------
0 8 11 22 33 78 65 66 /////////////
基数i为:7
基数定位的结果为:
------////-------
0 8 11 22 33 66 65 78 /////////////
基数i为:6
基数定位的结果为:
------////-------
0 8 11 22 33 65 66 78 /////////////
0 8 11 22 33 65 66 78 

快速排序设计到了递归,有点不好理解,相关东西可以网上多查看一下

你可能感兴趣的:(java的快速排序)