1 public class QuickSort {
 2     public static void sort(int[] a, int lo, int hi) {
 3         int start = lo;
 4         int end   = hi;
 5         int key   = a[lo];
 6         
 7         while(start < end) {
 8             while(start < end && a[end] >= key) {
 9                 end--;
10             }
11                 
12             if(a[end] <= key) {
13                 int temp = a[end];
14                 a[end] = a[start];
15                 a[start] = temp;
16             }
17             
18             while(start < end && a[start] <= key) {
19                 start++;
20             }
21             
22             if(a[start] >= key) {
23                 int temp = a[start];
24                 a[start] = a[end];
25                 a[end] = temp;
26             }
27         }
28         
29         if(lo < start) { sort(a, lo, start - 1); }
30         if(end < hi) { sort(a, end + 1, hi); }
31     }
32 }
View Code

相关文章:

  • 2022-01-15
  • 2021-12-06
  • 2021-12-02
  • 2021-11-24
  • 2021-11-19
  • 2021-08-21
  • 2021-07-19
  • 2021-12-09
猜你喜欢
  • 2021-12-09
  • 2021-05-12
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
相关资源
相似解决方案