Bläddra i källkod

Merge pull request #901 from FridaTveit/SaddlePointsImplementComparable

saddle-points: make MatrixCoordinate implement Comparable
Stuart Kent 9 år sedan
förälder
incheckning
4e6c4ca8da

+ 7
- 1
exercises/saddle-points/.meta/src/reference/java/MatrixCoordinate.java Visa fil

1
-class MatrixCoordinate {
1
+class MatrixCoordinate implements Comparable<MatrixCoordinate> {
2
     private final int row;
2
     private final int row;
3
     private final int col;
3
     private final int col;
4
 
4
 
30
         result = 31 * result + col;
30
         result = 31 * result + col;
31
         return result;
31
         return result;
32
     }
32
     }
33
+
34
+    @Override
35
+    public int compareTo(MatrixCoordinate o) {
36
+        int rowComparison = Integer.compare(row, o.row);
37
+        return (rowComparison == 0) ? Integer.compare(col, o.col) : rowComparison;
38
+    }
33
 }
39
 }

+ 7
- 1
exercises/saddle-points/src/main/java/MatrixCoordinate.java Visa fil

1
-class MatrixCoordinate {
1
+class MatrixCoordinate implements Comparable<MatrixCoordinate> {
2
     private final int row;
2
     private final int row;
3
     private final int col;
3
     private final int col;
4
 
4
 
30
         result = 31 * result + col;
30
         result = 31 * result + col;
31
         return result;
31
         return result;
32
     }
32
     }
33
+
34
+    @Override
35
+    public int compareTo(MatrixCoordinate o) {
36
+        int rowComparison = Integer.compare(row, o.row);
37
+        return (rowComparison == 0) ? Integer.compare(col, o.col) : rowComparison;
38
+    }
33
 }
39
 }