CJCoding With Joseph
15free / daySign inCreate account

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() and toString() 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 save items[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
Topics:
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.