-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDequeStack.java
More file actions
36 lines (29 loc) · 768 Bytes
/
Copy pathDequeStack.java
File metadata and controls
36 lines (29 loc) · 768 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
35
36
package com.company;
import java.util.AbstractCollection;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
/**
* Created by sky on 5/21/15.
* Implements a stack using an ArrayDeque. Useful for information
* hiding to prevent abuse of a Deque intended as a Stack.
*/
public class DequeStack<T> extends AbstractCollection<T> implements Stack<T> {
private final Deque<T> deque = new ArrayDeque<T>();
@Override
public void push(T object) {
deque.addFirst(object);
}
@Override
public T pop() {
return deque.removeFirst();
}
@Override
public Iterator<T> iterator() {
return deque.iterator();
}
@Override
public int size() {
return deque.size();
}
}