fork download
  1. import java.util.Comparator;
  2.  
  3. /**
  4.  * Example 132 - A Comparator for the Integer Class
  5.  */
  6.  
  7. class IntComparator implements Comparator<Integer> {
  8.  
  9. @Override
  10. public int compare(Integer v1, Integer v2) {
  11. return v1 < v2 ? -1 : v1 > v2 ? +1 : 0;
  12. }
  13. }
  14.  
  15. class IntegerComparator {
  16.  
  17. public static <T> void qsort(T[] arr, Comparator<T> cmp, int a, int b) {
  18. if (a < b) {
  19. int i = a, j = b;
  20. T x = arr[(i + j) / 2];
  21.  
  22. do {
  23. while (cmp.compare(arr[i], x) < 0) i++;
  24. while (cmp.compare(x, arr[j]) < 0) j--;
  25.  
  26. if ( i <= j) {
  27. T tmp = arr[i];
  28. arr[i] = arr[j];
  29. arr[j] = tmp;
  30. i++;
  31. j--;
  32. }
  33.  
  34. } while (i <= j);
  35.  
  36. qsort(arr, cmp, a, j);
  37. qsort(arr, cmp, i, b);
  38. }
  39. }
  40.  
  41. public static void main(String[] args) {
  42. Integer[] ia = {30, 20, 10, 5, 6, 99};
  43. GenericQuickSort.<Integer>qsort(ia, new IntComparator(), 0, ia.length-1);
  44. for(Integer i: ia) {
  45. System.out.println(i);
  46. }
  47.  
  48. }
  49.  
  50.  
  51. }
  52.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:43: error: cannot find symbol
        GenericQuickSort.<Integer>qsort(ia, new IntComparator(), 0, ia.length-1);
        ^
  symbol:   variable GenericQuickSort
  location: class IntegerComparator
1 error
stdout
Standard output is empty