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

图解快数排序法

时间:2018-02-06 12:51:19      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:技术   system   main   stat   ==   --   http   string   code   

快速排序图解:

技术分享图片

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

==========================================================================================================================

==========================================================================================================================

java 代码的实现:

技术分享图片
 1 package main.test;
 2 
 3 public class KSSort {
 4     public static int Partition(int[] a, int p, int r) {
 5         int x = a[r - 1];
 6         int i = p - 1;
 7         int temp;
 8         for (int j = p; j <= r - 1; j++) {
 9             if (a[j - 1] <= x) {
10 // 交换(a[j-1],a[i-1]);
11                 i++;
12                 temp = a[j - 1];
13                 a[j - 1] = a[i - 1];
14                 a[i - 1] = temp;
15             }
16         }
17 //交换(a[r-1,a[i+1-1]);
18         temp = a[r - 1];
19         a[r - 1] = a[i + 1 - 1];
20         a[i + 1 - 1] = temp;
21         return i + 1;
22     }
23 
24 
25     public static void QuickSort(int[] a,int p,int r){
26         if(p<r){
27             int q=Partition(a,p,r);
28             QuickSort(a,p,q-1);
29             QuickSort(a,q+1,r);
30         }
31     }
32 
33     static void print(int[] a) {
34         for (int values : a
35                 ) {
36             System.out.print(values+" | ");
37         }
38     }
39 
40 
41     public static void main(String[] args) {
42         int[] a={7,10,3,5,4,6,2,8,1,9};
43         QuickSort(a,1,10);
44         print(a);
45 
46 
47     }
48 
49 
50 }
View Code

 

图解快数排序法

标签:技术   system   main   stat   ==   --   http   string   code   

原文地址:https://www.cnblogs.com/linbo3168/p/8421430.html

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