Edited at

Javaでクイックソート

More than 3 years have passed since last update.


QuickSort.java

import java.util.Arrays;

public class QuickSort {
public static void main(String[] args) {
int[] arr = {4, 5, 1, 6, 9, 2, 8, 3, 7, 0};
Arrays.stream(quickSort(arr, 0, arr.length-1)).forEach(
e -> System.out.println(e));
}
public static int[] quickSort(int[] arr, int left, int right) {
if(left<=right) {
int p = arr[(left+right)/2];
int l = left;
int r = right;
while(l <= r) {
while(arr[l] < p) l++;
while(arr[r] > p) r--;

if(l<=r) {
int tmp = arr[l];
arr[l] = arr[r];
arr[r] = tmp;
l++;
r--;
}
}

quickSort(arr, left, r);
quickSort(arr, l, right);
}
return arr;
}
}