fork download
  1. public class Main{
  2. public static void main (String[] args){
  3. int[] x = {6, 3, 1, 7, 0, 4, 8, 5, 2, 9};
  4. quickSort(x, 0, 9);
  5. for (int i = 0; i < x.length; i++){
  6. System.out.print(x[i]);
  7. }
  8. }
  9. //基本挿入法(クイックソート)
  10. public static void quickSort(int[] arr, int left, int right){
  11. if (left <= right) {
  12. int p = arr[(left+right) / 2];
  13. int l = left;
  14. int r = right;
  15.  
  16. while(l <= r) {
  17. while(arr[l] < p){ l++; }
  18. while(arr[r] > p){ r--; }
  19.  
  20. if (l <= r) {
  21. int tmp = arr[l];
  22. arr[l] = arr[r];
  23. arr[r] = tmp;
  24. l++;
  25. r--;
  26. }
  27. }
  28.  
  29. quickSort(arr, left, r);
  30. quickSort(arr, l, right);
  31. }
  32. }
  33. }
Success #stdin #stdout 0.06s 380160KB
stdin
Standard input is empty
stdout
0123456789