import java.text.SimpleDateFormat;
import java.util.Date;
public class QuickSort {
public static void main(String[] args) {
int[] array = new int[100000000];
for (int i = 0; i < 100000000; i++) {
array[i] = (int) (Math.random() * 2140000000);
}
Date startDate = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("start :" + simpleDateFormat.format(startDate));
quickSort(array, 0, array.length - 1);
Date endDate = new Date();
System.out.println("end :" + simpleDateFormat.format(endDate));
}
public static void quickSort(int[] array, int left, int right) {
int l = left;
int r = right;
int pivot = array[(left + right) / 2];
while (l < r) {
while (array[l] < pivot) {
l++;
}
while (array[r] > pivot) {
r--;
}
if (l >= r) {
break;
}
array[l] = array[l] + array[r] - (array[r] = array[l]);
if (array[l] == pivot) {
r--;
}
if (array[r] == pivot) {
l++;
}
}
if (l == r) {
l++;
r--;
}
if (left < r) {
quickSort(array, left, r);
}
if (right > l) {
quickSort(array, l, right);
}
}
}
版权声明:本文为ytc958374686原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。