|
| 1 | +/* |
| 2 | + * An interface describing the operations to support the "double-ended |
| 3 | + * queue" abstract data type, known as the deque and pronounced as |
| 4 | + * "deck". Elements can be added to and removed from the head and the |
| 5 | + * tail of the deque. |
| 6 | + * |
| 7 | + * In this interface, elements can be any Object type or null. |
| 8 | + */ |
| 9 | +public interface InstructuresDeque |
| 10 | +{ |
| 11 | + /* |
| 12 | + * Returns the number of elements in the deque. |
| 13 | + */ |
| 14 | + int size(); |
| 15 | + |
| 16 | + /* |
| 17 | + * Returns `true` if there are no elements in the deque. |
| 18 | + */ |
| 19 | + boolean isEmpty(); |
| 20 | + |
| 21 | + /* |
| 22 | + * Adds the given element to the top of the deque. (This operation |
| 23 | + * is known as "push" for stacks, and "unshift" for sequences.) |
| 24 | + * |
| 25 | + * Throws IllegalStateException if this method is called when the |
| 26 | + * deque is full. |
| 27 | + */ |
| 28 | + void addTop(Object element); |
| 29 | + |
| 30 | + /* |
| 31 | + * Adds the given element to the bottom of the deque. (This |
| 32 | + * operation is known as "enqueue [as a verb]" for queues.) |
| 33 | + * |
| 34 | + * Throws IllegalStateException if this method is called when the |
| 35 | + * deque is full. |
| 36 | + */ |
| 37 | + void addBottom(Object element); |
| 38 | + |
| 39 | + /* |
| 40 | + * Removes the deque's top-most element, returning its value. (This |
| 41 | + * operation is known as "pop" for stacks, "shift" for sequences, |
| 42 | + * and "dequeue [as a verb]" for queues.) |
| 43 | + * |
| 44 | + * Throws IllegalStateException if this method is called when the |
| 45 | + * deque is empty. |
| 46 | + */ |
| 47 | + Object removeTop(); |
| 48 | + |
| 49 | + /* |
| 50 | + * Removes the deque's bottom-most element, returning its value. |
| 51 | + * |
| 52 | + * Throws IllegalStateException if this method is called when the |
| 53 | + * deque is empty. |
| 54 | + */ |
| 55 | + Object removeBottom(); |
| 56 | + |
| 57 | + /* |
| 58 | + * If the deque is non-empty, returns the value of the deque's |
| 59 | + * top-most element without removing it; returns null |
| 60 | + * otherwise. (This operation is known as "peek" for stacks, and |
| 61 | + * "first" for sequences.) |
| 62 | + * |
| 63 | + * Unlike `removeTop`, `top` does not throw an exception. |
| 64 | + */ |
| 65 | + Object top(); |
| 66 | + |
| 67 | + /* |
| 68 | + * If the deque is non-empty, returns the value of the deque's |
| 69 | + * bottom-most element without removing it; returns null |
| 70 | + * otherwise. (This operation is known as "last" for sequences.) |
| 71 | + * |
| 72 | + * Unlike `removeBottom`, `bottom` does not throw an exception. |
| 73 | + */ |
| 74 | + Object bottom(); |
| 75 | +} |
0 commit comments