fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Sorter<Integer> idSorter = new Sorter<>(new idComparator());
  13. }
  14.  
  15. static class Sorter<T extends Comparable> {
  16.  
  17. Comparator<T> comparator;
  18. int switches = 0,
  19. compares = 0;
  20.  
  21. public Sorter(Comparator<T> comparator) {
  22. this.comparator = comparator;
  23. }
  24.  
  25. public Sorter() {
  26. this.comparator = null;
  27. }
  28.  
  29. protected int compare(T first, T second) {
  30. if (this.comparator == null) {
  31. int cmp = first.compareTo(second);
  32. this.compares++;
  33. return cmp;
  34. }
  35. // return was missing
  36. return 0;
  37. }
  38. }
  39.  
  40. static class idComparator implements Comparator<Integer> {
  41.  
  42. public int compare(Integer first, Integer second) {
  43. return first > second? 1: first == second? 0: 1;
  44. }
  45. }
  46.  
  47. static class Person {}
  48. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
Standard output is empty