码迷,mamicode.com
首页 > 编程语言 > 详细

Sort--快速排序

时间:2015-04-26 01:13:39      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

快速排序

 1 public class QuickSort{
 2     
 3     public static int Partition(int[] a,int low,int high){
 4         int pivotkey=a[low];
 5         while(low<high){
 6             while(pivotkey<=a[high]&&low<high) high--;
 7             a[low++]=a[high];
 8             while(pivotkey>=a[low]&&low<high)  low++;
 9             a[high--]=a[low];
10         }
11         a[low]=pivotkey;
12         return low;        
13     }
14     
15     public static void quicksort(int[] a,int low,int high){
16         int pivotkey;
17         if(low<high){
18             pivotkey = Partition(a,low,high);
19             quicksort(a,low,pivotkey-1);
20             quicksort(a,pivotkey+1,high);
21         }
22     }
23     public static void main(String[] args){
24         int[] a={49,38,65,97,76,13,27};
25         quicksort(a,0,a.length-1);
26          for(int i=0;i<a.length;i++){
27              System.out.println(a[i]);
28          }
29     }
30 }

 

Sort--快速排序

标签:

原文地址:http://www.cnblogs.com/daneres/p/4457172.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!