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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package edu.caltech.cs2.interfaces;
/**
* This interface represents a deque - a data structure that can add and remove elements from either end of a list.
* @param <E> Element type
*/
public interface IDeque<E> extends ICollection<E> {
/**
* Add an element to the front end of the deque.
* @param e Element to add
*/
public void addFront(E e);
/**
* Add an element to the back end of the deque.
* @param e Element to add
*/
public void addBack(E e);
/**
* Adds an element to the collection.
* @param e Element to add
*/
@Override
default public void add(E e) {
this.addBack(e);
}
/**
* Adds a collection of elements to this collection.
* @param c Collection of elements to add
*/
default public void addAll(ICollection<E> c) {
for (E e : c) {
this.add(e);
}
}
/**
* Removes and returns the element at the front end of the deque. Returns null if deque is empty.
* @return Element at front, if one exists; null otherwise
*/
public E removeFront();
/**
* Removes and returns the element at the back end of the deque. Returns null if deque is empty.
* @return Element at back, if one exists; null otherwise
*/
public E removeBack();
/**
* Removes all elements in the deque.
*/
@Override
default public void clear() {
while (!this.isEmpty()) {
this.removeBack();
}
}
/**
* Returns (but does not remove) the element at one end of the deque. Returns null if deque is empty.
* Note: The side you peek from should be chosen such that both the IQueue and IStack interfaces are implemented correctly.
* @return Element at one end, if one exists; null otherwise
*/
public E peek();
/**
* Returns (but does not remove) the element at the front end of the deque. Returns null if deque is empty.
* @return Element at front, if one exists; null otherwise
*/
public E peekFront();
/**
* Returns (but does not remove) the element at the back end of the deque. Returns null if deque is empty.
* @return Element at back, if one exists; null otherwise
*/
public E peekBack();
}