Browse Source

Pair->min,max

vvmk 6 years ago
parent
commit
398f30ff23
1 changed files with 3 additions and 3 deletions
  1. 3
    3
      src/main/java/Pair/Pair.java

+ 3
- 3
src/main/java/Pair/Pair.java View File

@@ -7,7 +7,7 @@ package Pair;
7 7
  * min -> returns the minimum of the pair
8 8
  * max -> returns the maximum of the pair
9 9
  */
10
-public class Pair<E> {
10
+public class Pair<E extends Comparable<E>> {
11 11
     private E first;
12 12
     private E second;
13 13
 
@@ -25,10 +25,10 @@ public class Pair<E> {
25 25
     }
26 26
 
27 27
     public E min() {
28
-        return null;
28
+        return (first.compareTo(second) < 1) ? first : second;
29 29
     }
30 30
 
31 31
     public E max() {
32
-        return null;
32
+        return (first.compareTo(second) > 0) ? first : second;
33 33
     }
34 34
 }