排序算法之快速排序(java实现)

 1 package com.javaTest300;
 2 
 3 public class Test039 {
 4 
 5  public static void main(String[] args) {// 快速排序
 6 
 7   int a[]={2,3,8,10,5,1,8,78,35,12};  
 8 
 9  System.out.println("----排序前-----");  
10 
11  for (int i = 0; i < a.length; i++) {    
12 
13 System.out.print(a[i]+" ");   
14 
15 }  
16 
17  System.out.println();  
18 
19  System.out.println("----排序后-----");  
20 
21  Quick_Sort(a, 0, a.length-1);
22 
23   for (int i = 0; i < a.length; i++) {  
24 
25   System.out.print(a[i]+" ");   
26 
27 }  
28 
29  System.out.println();
30 
31  }  
32 
33 public static void  Quick_Sort(int arr[],int start,int end) {     
34 
35 if(arr==null || end-start+1<2)
36 
37 {
38 
39 return ;
40 
41 }
42 
43 else
44 
45 {
46 
47   if(start<end){   
48 
49  int privote=Partition(arr,start,end);    
50 
51  Quick_Sort(arr, start, privote-1);   
52 
53   Quick_Sort(arr, privote+1, end);
54 
55    }
56 
57 }
58 
59  }  
60 
61 public static int Partition(int arr[],int low,int high){
62 
63   int tmp=arr[low];   
64 
65 while(low<high){   
66 
67  while(low<high&&tmp<=arr[high]){    
68 
69  high--;  
70 
71   }    
72 
73 arr[low]=arr[high];  
74 
75  while(low<high&&arr[low]<=tmp){
76 
77    low++;   
78 
79 }  
80 
81  arr[high]=arr[low];  
82 
83 }   
84 
85 arr[low]=tmp;   return low;
86 
87 }
88 
89 }

 本文为博主原创文章,转载请注明出处:http://www.cnblogs.com/ysw-go/
1、本博客的原创原创文章,都是本人平时学习所做的笔记,如有错误,欢迎指正。
2、如有侵犯您的知识产权和版权问题,请通知本人,本人会即时做出处理文章。
3、本博客的目的是知识交流所用,转载自其它博客或网站,作为自己的参考资料的,感谢这些文章的原创人员

原文地址:https://www.cnblogs.com/ysw-go/p/4878742.html