瀏覽代碼

all but powersets

Lauren Green 6 年之前
父節點
當前提交
d2b6a85aa4

+ 3
- 1
src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java 查看文件

@@ -10,7 +10,9 @@ public class GenericUtils {
10 10
 
11 11
         List<T> result = new ArrayList<>();
12 12
 
13
-
13
+//        for (int i = 0; i < originalSet.size(); i++) {
14
+//            T[] arr = originalSet
15
+//        }
14 16
 
15 17
 
16 18
         return (Iterable<? extends Iterable<T>>) result;

+ 24
- 5
src/main/java/rocks/zipcode/io/quiz4/generics/MyStack.java 查看文件

@@ -1,25 +1,44 @@
1 1
 package rocks.zipcode.io.quiz4.generics;
2 2
 
3
+import java.util.Iterator;
4
+import java.util.Stack;
5
+
3 6
 /**
4 7
  * @author leon on 11/12/2018.
5 8
  */
6
-public class MyStack<SomeType> {
9
+public class MyStack<SomeType> implements Iterable {
10
+
11
+    Stack stack;
12
+
7 13
     public MyStack() {
8
-        throw new UnsupportedOperationException("Method not yet implemented");
14
+
15
+        this.stack = new Stack();
9 16
     }
10 17
 
11 18
     public Boolean isEmpty() {
12
-        return null;
19
+        return this.stack.isEmpty();
13 20
     }
14 21
 
15 22
     public void push(SomeType i) {
23
+        this.stack.push(i);
16 24
     }
17 25
 
18 26
     public SomeType peek() {
19
-        throw new UnsupportedOperationException("Method not yet implemented");
27
+
28
+        if(isEmpty()) {
29
+            return null;
30
+        }
31
+
32
+        return (SomeType) this.stack.peek();
20 33
     }
21 34
 
22 35
     public SomeType pop() {
23
-        return null;
36
+
37
+        return (SomeType) this.stack.pop();
38
+    }
39
+
40
+    @Override
41
+    public Iterator iterator() {
42
+        return this.stack.iterator();
24 43
     }
25 44
 }