Skip to content

New exercise : fundamentals - resizing array queue#22

Open
feforet wants to merge 2 commits intopschaus:mainfrom
feforet:add-ResizingArrayQueue
Open

New exercise : fundamentals - resizing array queue#22
feforet wants to merge 2 commits intopschaus:mainfrom
feforet:add-ResizingArrayQueue

Conversation

@feforet
Copy link

@feforet feforet commented Dec 4, 2025

Suggestion for a new exercise to add in fundamentals

Copilot AI review requested due to automatic review settings December 4, 2025 15:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ResizingArrayQueue with 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.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment refers to "head of the stack" but this is a queue implementation, not a stack. It should say "head of the queue".

Suggested change
* 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.

Copilot uses AI. Check for mistakes.
* 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]
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "the remove method" but the actual method name is "dequeue". This should be corrected to reference the proper method name.

Suggested change
* - the remove method [The NoSuchElementException is thrown when the queue is empty]
* - the dequeue method [The NoSuchElementException is thrown when the queue is empty]

Copilot uses AI. Check for mistakes.
Comment on lines +138 to +148

@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;
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Suggested change
@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--;

Copilot uses AI. Check for mistakes.

@Override
public Item next() {
if (nOp != getnOp()) throw new ConcurrentModificationException();
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next() method doesn't check if there are elements remaining before accessing the array. It should call hasNext() and throw NoSuchElementException if false.

Suggested change
if (nOp != getnOp()) throw new ConcurrentModificationException();
if (nOp != getnOp()) throw new ConcurrentModificationException();
if (!hasNext()) throw new NoSuchElementException();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant