|
@@ -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
|
}
|