-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathStack.java
More file actions
34 lines (27 loc) · 710 Bytes
/
Stack.java
File metadata and controls
34 lines (27 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// onjava/Stack.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// A Stack class built with an ArrayDeque
package onjava;
import java.util.ArrayDeque;
import java.util.Deque;
public class Stack<T> {
private Deque<T> storage = new ArrayDeque<>();
public void push(T v) {
storage.push(v);
}
public T peek() {
return storage.peek();
}
public T pop() {
return storage.pop();
}
public boolean isEmpty() {
return storage.isEmpty();
}
@Override
public String toString() {
return storage.toString();
}
}