Java程序快速排序是怎样的,举个例子说明一下

2022-07-26 综合 98阅读
public class QuickSort {        
    private static void QuickSort(int[] array,int start,int end)      {              if(start            int key=array[start];//初始化保存基元               
            int i=start,j;//初始化i,j              
            for(j=start+1;j<=end;j++)                                
                if(array[j]                      array[j]=array[i+1];                     
                      array[i+1]=temp;                      
                      i++;                  
                }                                
           }              
           array[start]=array[i];//交换i处元素和基元               
           array[i]=key;              
           QuickSort(array, start, i-1);//递归调用               
           QuickSort(array, i+1, end);                        
        }                
   }      
   public static void main(String[] args)      {          
       int[] array=new int[]{11,213,134,44,77,78,23,43};          
       QuickSort(array, 0, array.length-1);         
       for(int i=0;i           System.out.println((i+1)+"th:"+array[i]);          
       }      
   }
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com