Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the given IntegerQueue interface so that it is a generic Queue interface

ID: 3811946 • Letter: M

Question

Modify the given IntegerQueue interface so that it is a generic Queue interface (nameit IQueue) and write a generic class to implement it. You need to show therepresentation and some plausible code for the constructor and enqueue operations.No need to write contracts or any other assertions. This question says plausible codebecause no correspondence, etc. is given or needs to be written.

public class Queue3 implements IntegerQueue {

/**

* invariant 0 <= front <= contents.length;

* correspondence conceptual this =   contents[front..contents.length – 1];

*/ Integer[] contents; int front; Queue3(int len) {

}  Integer dequeue() {

}

}

Explanation / Answer


public class Queue3 implements IntegerQueue {
/**
* invariant 0 <= front <= contents.length;
* correspondence conceptual this = contents[front..contents.length – 1];
*/
Integer[ ] contents;
int front;

Queue3(int len) {
   contents = new Integer[len];
   front = 0;
}
Integer dequeue() {
   if(front == 0)
       return null;
   Integer x = contents[front];
   front = front + 1;
   return x;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote