← Back to Data Structures & Algorithms
Question 433
Add to the Front of a Deque
Add to the Front of a Deque
ArrayDequeInt holds up to 5 ints in a circular array. isEmpty, isFull, size, addLast, removeFirst and toString are already written; only addFirst is missing.
Requirements:
1. addFirst(int value) returns false when the deque is already full.
2. Otherwise move front backward one slot, wrapping around to the end of the array when it falls off index 0.
3. Store value at the new front, grow the size, and return true.
Do NOT write a main method.Expected Output:
true true true Deque: 30 20 10 3 30 Deque: 20 10
= newline. The output ends with a newline — print one after the last line.
Hints2 available
Sign in to use hintsTopics:
Data Structures & AlgorithmsDeques
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.