-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstructureDeque.java
More file actions
75 lines (68 loc) · 2.1 KB
/
InstructureDeque.java
File metadata and controls
75 lines (68 loc) · 2.1 KB
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
/*
* An interface describing the operations to support the "double-ended
* queue" abstract data type, known as the deque and pronounced as
* "deck". Elements can be added to and removed from the head and the
* tail of the deque.
*
* In this interface, elements can be any Object type or null.
*/
public interface InstructuresDeque
{
/*
* Returns the number of elements in the deque.
*/
int size();
/*
* Returns `true` if there are no elements in the deque.
*/
boolean isEmpty();
/*
* Adds the given element to the top of the deque. (This operation
* is known as "push" for stacks, and "unshift" for sequences.)
*
* Throws IllegalStateException if this method is called when the
* deque is full.
*/
void addTop(Object element);
/*
* Adds the given element to the bottom of the deque. (This
* operation is known as "enqueue [as a verb]" for queues.)
*
* Throws IllegalStateException if this method is called when the
* deque is full.
*/
void addBottom(Object element);
/*
* Removes the deque's top-most element, returning its value. (This
* operation is known as "pop" for stacks, "shift" for sequences,
* and "dequeue [as a verb]" for queues.)
*
* Throws IllegalStateException if this method is called when the
* deque is empty.
*/
Object removeTop();
/*
* Removes the deque's bottom-most element, returning its value.
*
* Throws IllegalStateException if this method is called when the
* deque is empty.
*/
Object removeBottom();
/*
* If the deque is non-empty, returns the value of the deque's
* top-most element without removing it; returns null
* otherwise. (This operation is known as "peek" for stacks, and
* "first" for sequences.)
*
* Unlike `removeTop`, `top` does not throw an exception.
*/
Object top();
/*
* If the deque is non-empty, returns the value of the deque's
* bottom-most element without removing it; returns null
* otherwise. (This operation is known as "last" for sequences.)
*
* Unlike `removeBottom`, `bottom` does not throw an exception.
*/
Object bottom();
}