← Back to Data Structures & Algorithms
Question 439
Guard an Empty Array Queue
Guard an Empty Array Queue
ShiftQueue can already accept values and print itself, but nothing stops it reading a slot it does not own. Three missing methods have to agree. Requirements: 1.isEmpty()reports whether the queue holds no values. 2.peek()returns -1 when empty, otherwise the front value, removing nothing. 3.dequeue()also returns -1 when empty, otherwise savesitems[0], shifts the later values one slot left, decreases size and returns the saved value. 4.peek()anddequeue()must both decide the empty case by callingisEmpty(). Do NOT write a main method.
Expected Output:
true -1 -1 false 4 Queue: 4 8 4 8 true -1
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Data Structures & AlgorithmsQueues
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.