leecode更新
This commit is contained in:
parent
03bc9f9c6b
commit
892b12b23d
|
|
@ -0,0 +1,17 @@
|
|||
package com.cqu.ge.test;
|
||||
|
||||
/**
|
||||
* @BelongsProject: GE_Migrating_data
|
||||
* @BelongsPackage: com.cqu.ge.test
|
||||
* @Author: marklue
|
||||
* @CreateTime: 2023/5/3 14:28
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class try1 {
|
||||
static Try try11;
|
||||
|
||||
public static void main(String[] args){
|
||||
try11.equals(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package com.markilue.leecode.sort;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @BelongsProject: Leecode
|
||||
* @BelongsPackage: com.markilue.leecode.sort
|
||||
* @Author: marklue
|
||||
* @CreateTime: 2023/4/23 20:27
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class QuickSort1 {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
int[] nums={8,5,7,6,9,2,4,3,1};
|
||||
quickSort(nums);
|
||||
System.out.println(Arrays.toString(nums));
|
||||
}
|
||||
|
||||
|
||||
public void quickSort(int[] nums) {
|
||||
quickSort(nums,0,nums.length-1);
|
||||
}
|
||||
|
||||
public void quickSort(int[] nums, int left, int right) {
|
||||
if (left > right) return;
|
||||
int partition = partition(nums, left, right);
|
||||
quickSort(nums, left, partition-1);
|
||||
quickSort(nums,partition+1,right);
|
||||
|
||||
}
|
||||
|
||||
public int partition(int[] nums, int left, int right) {
|
||||
|
||||
if (left > right) return left;
|
||||
|
||||
int start = left;
|
||||
int end = right + 1;
|
||||
|
||||
while (start < end) {
|
||||
while (start < right && nums[++start] < nums[left]) {
|
||||
|
||||
}
|
||||
|
||||
while (end > left && nums[--end] > nums[left]) {
|
||||
|
||||
}
|
||||
if (start >= end) {
|
||||
break;
|
||||
}
|
||||
swap(nums, start, end);
|
||||
}
|
||||
swap(nums,left,end);
|
||||
|
||||
return end;
|
||||
}
|
||||
|
||||
private void swap(int[] nums, int start, int end) {
|
||||
int temp = nums[start];
|
||||
nums[start] = nums[end];
|
||||
nums[end] = temp;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue