← Back to Data Structures & Algorithms
Question 441
Circular Queue With front and rear
Circular Queue With front and rear
RingQueue tracks front and rear instead of a size counter, which creates a problem: front == rear would mean both empty and completely full. The fix is to waste one slot on purpose - the queue calls itself full one slot early, so front == rear can only mean empty. With CAPACITY 5 that leaves room for 4 values.size()andtoString()are written. Requirements: 1.isEmpty()is true when front == rear. 2.isFull()is true when (rear + 1) % CAPACITY == front. 3.enqueue(int value): return false when full, otherwise store the value at rear, move rear forward with % CAPACITY and return true. 4.dequeue(): return -1 when empty, otherwise saveitems[front], move front forward with % CAPACITY and return the saved value. Do NOT write a main method.
Expected Output:
true true true true true true false Queue: 10 20 30 40 4
= 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.