Java快速排序

快速排序:

 1 public int Partition(int[] nums, int low, int high) {
 2         int pivot = nums[low];
 3 
 4         while (low < high) {
 5             while (nums[high] >= pivot && low < high)
 6                 high--;
 7             nums[low] = nums[high];
 8             while (nums[low] < pivot && low < high)
 9                 low++;
10             nums[high] = nums[low];
11         }
12         nums[low] = pivot;
13         return low;
14     }
15 
16     public void QuickSort(int[] nums, int left, int right) {
17         if (nums == null || nums.length < 0)
18             return;
19         if (left < right) {
20             int i = Partition(nums, left, right);
21             QuickSort(nums, left, i - 1);
22             QuickSort(nums, i + 1, right);
23         }
24     }

 

posted @ 2016-05-25 14:39  Acode  阅读(211)  评论(0编辑  收藏  举报
您是本站第访问量位访问者!