Home > 类库下载 > java类库 > Java quick sort

Java quick sort

巴扎黑
Release: 2016-12-03 11:58:19
Original
2658 people have browsed it

public static void quickSort(double[] array, int i, int j) {
if (j <= i)
return;
int pivotIndext = (i + j) / 2;
swap(array, pivotIndext, j);
int k = partition(array, i - 1, j, array[j]);
swap(array, j, k);
quickSort(array, i, k - 1);
quickSort(array, k, j);
}
public static int partition(double[] array, int left, int right, double pivot) {
do {
while (array[++left] < pivot)
;
while ((left < right) & (pivot < array[--right]))
;
swap(array, left, right);
} while (left < right);
return 0;
}
public static void swap(double[] data, int a, int b) {
double t = data[a];
data[a] = data[b];
data[b] = t;
}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template