package com.acwer.queue;
import java.util.Arrays;
import java.util.Date;
import java.util.Random;
public class 快速排序2 {
public static void main(String[] args) {
int[] arr=new int[10000];
for (int i = 0; i < arr.length; i++) {
arr[i]=(new Random().nextInt(100));
}
long ts=new Date().getTime();
QuickSort(arr,0,arr.length-1);
System.out.println((new Date().getTime()-ts)*1.0/1000);
//System.out.println(Arrays.toString(arr));
}
static void QuickSort(int[] arr,int left,int right){
if(left>right) return;
int l=left,r=right;
int std=arr[r];
while (l<r){
while (l<r &&arr[l]<=std) l++;
arr[r]=arr[l];
while (l<r && arr[r]>=std) r--;
arr[l]=arr[r];
}
arr[l]=std;
QuickSort(arr,left,r-1);
QuickSort(arr,r+1,right);
}
}
JAVA 快速排序
最新推荐文章于 2024-08-25 22:29:30 发布