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 }
作者: Acode
出处: http://www.cnblogs.com/acode/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出, 原文链接 如有问题, 可留言咨询.