浏览代码

Implement Combiner methods

vvmk 6 年前
父节点
当前提交
d67c8576f9
共有 2 个文件被更改,包括 10 次插入7 次删除
  1. 1
    0
      src/main/java/ArrayListCombiner/ArrayListCombiner.java
  2. 9
    7
      src/main/java/Pair/Arrays.java

+ 1
- 0
src/main/java/ArrayListCombiner/ArrayListCombiner.java 查看文件

@@ -10,6 +10,7 @@ import java.util.ArrayList;
10 10
  */
11 11
 public class ArrayListCombiner {
12 12
     public static <E> void superCombiner(ArrayList<? super E> parent, ArrayList<E> child) {
13
+        
13 14
     }
14 15
 
15 16
     public static <E> void extendCombiner(ArrayList<E> parent, ArrayList<? extends E> child) {

+ 9
- 7
src/main/java/Pair/Arrays.java 查看文件

@@ -1,6 +1,8 @@
1 1
 package Pair;
2 2
 
3 3
 import java.util.ArrayList;
4
+import java.util.Collections;
5
+import java.util.Comparator;
4 6
 
5 7
 /**
6 8
  * In here you must make firstLast, which will return a pair of the first element in the array list and the last
@@ -10,22 +12,22 @@ import java.util.ArrayList;
10 12
  * And a minmax method that returns a pair containing the largest and smallest items from the array list
11 13
  */
12 14
 public class Arrays {
13
-    public static <E> Pair<E> firstLast(ArrayList<E> a) {
15
+    public static <E extends Comparable<E>> Pair<E> firstLast(ArrayList<E> a) {
14 16
         E first = a.get(0);
15 17
         E second = a.get(a.size() - 1);
16 18
 
17 19
         return new Pair<>(first, second);
18 20
     }
19 21
 
20
-    public <E> E max(ArrayList<E> a) {
21
-        return null;
22
+    public <E extends Comparable<E>> E max(ArrayList<E> a) {
23
+        return Collections.max(a);
22 24
     }
23 25
 
24
-    public <E> E min(ArrayList<E> a) {
25
-        return null;
26
+    public <E extends Comparable<E>> E min(ArrayList<E> a) {
27
+        return Collections.min(a);
26 28
     }
27 29
 
28
-    public <E> Pair<E> minmax(ArrayList<E> a) {
29
-        return null;
30
+    public <E extends Comparable<E>> Pair<E> minmax(ArrayList<E> a) {
31
+        return new Pair<>(min(a), max(a));
30 32
     }
31 33
 }