소스 검색

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
  */
10
  */
11
 public class ArrayListCombiner {
11
 public class ArrayListCombiner {
12
     public static <E> void superCombiner(ArrayList<? super E> parent, ArrayList<E> child) {
12
     public static <E> void superCombiner(ArrayList<? super E> parent, ArrayList<E> child) {
13
+        
13
     }
14
     }
14
 
15
 
15
     public static <E> void extendCombiner(ArrayList<E> parent, ArrayList<? extends E> child) {
16
     public static <E> void extendCombiner(ArrayList<E> parent, ArrayList<? extends E> child) {

+ 9
- 7
src/main/java/Pair/Arrays.java 파일 보기

1
 package Pair;
1
 package Pair;
2
 
2
 
3
 import java.util.ArrayList;
3
 import java.util.ArrayList;
4
+import java.util.Collections;
5
+import java.util.Comparator;
4
 
6
 
5
 /**
7
 /**
6
  * In here you must make firstLast, which will return a pair of the first element in the array list and the last
8
  * In here you must make firstLast, which will return a pair of the first element in the array list and the last
10
  * And a minmax method that returns a pair containing the largest and smallest items from the array list
12
  * And a minmax method that returns a pair containing the largest and smallest items from the array list
11
  */
13
  */
12
 public class Arrays {
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
         E first = a.get(0);
16
         E first = a.get(0);
15
         E second = a.get(a.size() - 1);
17
         E second = a.get(a.size() - 1);
16
 
18
 
17
         return new Pair<>(first, second);
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
 }