New exercise : fundamentals - resizing array queue#22
New exercise : fundamentals - resizing array queue#22feforet wants to merge 2 commits intopschaus:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new exercise for implementing a resizing array-based queue data structure with FIFO (first-in-first-out) semantics. The exercise includes both the implementation class and comprehensive unit tests.
Key Changes:
- Implementation of
ResizingArrayQueuewith dynamic array resizing (doubles when full, halves when 1/4 full) - Test suite covering basic operations, wrap-around behavior, resizing, and iterator functionality
- Updated IDE configuration files
Reviewed changes
Copilot reviewed 2 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/fundamentals/ResizingArrayQueue.java | Main implementation of the resizing array queue with enqueue/dequeue operations, dynamic resizing, and fail-fast iterator |
| src/test/java/fundamentals/ResizingArrayQueueTest.java | Comprehensive test suite covering queue operations, resizing behavior, wrap-around, and iterator edge cases |
| .idea/vcs.xml | IDE VCS configuration |
| .idea/misc.xml | IDE project configuration for Maven and JDK settings |
| .idea/jarRepositories.xml | IDE Maven repository configuration |
| .idea/encodings.xml | IDE encoding settings for source files |
| .idea/compiler.xml | IDE compiler configuration for annotation processing |
| .idea/.gitignore | IDE-specific gitignore for workspace files |
Files not reviewed (6)
- .idea/.gitignore: Language not supported
- .idea/compiler.xml: Language not supported
- .idea/encodings.xml: Language not supported
- .idea/jarRepositories.xml: Language not supported
- .idea/misc.xml: Language not supported
- .idea/vcs.xml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * - the remove method [The NoSuchElementException is thrown when the queue is empty] | ||
| * - the iterator used to browse the queue in FIFO | ||
| * | ||
| * Hint : when the head of the stack reaches the end of the array, go back at its beginning. |
There was a problem hiding this comment.
The comment refers to "head of the stack" but this is a queue implementation, not a stack. It should say "head of the queue".
| * Hint : when the head of the stack reaches the end of the array, go back at its beginning. | |
| * Hint : when the head of the queue reaches the end of the array, go back at its beginning. |
| * You are asked to implement this Queue by completing the class see (TODO's) | ||
| * Most important methods are: | ||
| * - the enqueue method to add an element | ||
| * - the remove method [The NoSuchElementException is thrown when the queue is empty] |
There was a problem hiding this comment.
The comment says "the remove method" but the actual method name is "dequeue". This should be corrected to reference the proper method name.
| * - the remove method [The NoSuchElementException is thrown when the queue is empty] | |
| * - the dequeue method [The NoSuchElementException is thrown when the queue is empty] |
|
|
||
| @Override | ||
| public boolean hasNext() { | ||
| return currentHead != tail; | ||
| } | ||
|
|
||
| @Override | ||
| public Item next() { | ||
| if (nOp != getnOp()) throw new ConcurrentModificationException(); | ||
| Item current = q[currentHead]; | ||
| currentHead = (currentHead + 1) % q.length; |
There was a problem hiding this comment.
The hasNext() implementation is incorrect. It compares currentHead != tail, but this will fail when the queue is empty (both head and tail are 0). It should also track the number of items remaining. Consider using private int remaining = size; and checking remaining > 0 in hasNext(), then decrementing it in next().
| @Override | |
| public boolean hasNext() { | |
| return currentHead != tail; | |
| } | |
| @Override | |
| public Item next() { | |
| if (nOp != getnOp()) throw new ConcurrentModificationException(); | |
| Item current = q[currentHead]; | |
| currentHead = (currentHead + 1) % q.length; | |
| private int remaining = size; | |
| @Override | |
| public boolean hasNext() { | |
| return remaining > 0; | |
| } | |
| @Override | |
| public Item next() { | |
| if (nOp != getnOp()) throw new ConcurrentModificationException(); | |
| if (!hasNext()) throw new NoSuchElementException(); | |
| Item current = q[currentHead]; | |
| currentHead = (currentHead + 1) % q.length; | |
| remaining--; |
|
|
||
| @Override | ||
| public Item next() { | ||
| if (nOp != getnOp()) throw new ConcurrentModificationException(); |
There was a problem hiding this comment.
The next() method doesn't check if there are elements remaining before accessing the array. It should call hasNext() and throw NoSuchElementException if false.
| if (nOp != getnOp()) throw new ConcurrentModificationException(); | |
| if (nOp != getnOp()) throw new ConcurrentModificationException(); | |
| if (!hasNext()) throw new NoSuchElementException(); |
Suggestion for a new exercise to add in fundamentals