Skip to content

Commit

Permalink
排序算法-快速排序
Browse files Browse the repository at this point in the history
  • Loading branch information
BGMer7 committed Jul 25, 2022
1 parent 5c11a69 commit e6841e5
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/com/gatsby/utils/SortUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.gatsby.utils;

/**
* @ClassName: SortUtil
* @Description: 排序类
* @author: Gatsby
* @date: 2022/7/25 15:03
*/

public class SortUtil {
/**
* @MethodName: quickSort
* @Parameter: [nums, begin, end]
* @Return void
* @Description: 快速排序
* @author: Gatsby
* @date: 2022/7/25 15:20
*/
public static void quickSort(int[] nums, int begin, int end) {
if (begin < end) {
int pivot = nums[begin];
int i = begin;
int j = end;
while (i < j) {
while (i < j && nums[j] > pivot) {
j--;
}
if (i < j) {
nums[i] = nums[j];
i++;
}

while (i < j && nums[i] < pivot) {
i++;
}
if (i < j) {
nums[j] = nums[i];
j--;
}
}
nums[j] = pivot;
quickSort(nums, begin, j - 1);
quickSort(nums, j + 1, end);
}
}
}


0 comments on commit e6841e5

Please sign in to comment.