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

Consider a new kind of queue that allows only a single copy of an object in the

ID: 3759058 • Letter: C

Question

Consider a new kind of queue that allows only a single copy of an object in the queue. If an object is added to the queue, but it is already there, leave the queue unchanged. This queue has another operation moveToBack that takes an object in the queue and moves it to the back. If an object is not in the queue, the operation adds it at the back of the queue.

Create an interface NoDuplicatesQueueInterface that extends QueueInterface and save as NoDuplicatesQueueInterfaceYourLastName.java. Then write an array-based implementation of NoDuplicatesQueue and save as NoDuplicatesQueueYourLastName.java. Finally, write a program that adequately demonstrates your new class and save as DriverYourLastName.java.

Here is the QueueInterface:

Explanation / Answer

public interface NoDuplicatesQueueInterfaceYourLastName extends QueueInterface
{
// only overrridng the enque method..rest methods remain same
public void enqueue(T newEntry);

public void moveToBack(T entry);
}

public class NoDuplicatesQueueYourLastName implements NoDuplicatesQueueInterfaceYourLastName
{
Queue myQueue;

public void enqueue(T newEntry)
{
if(myQueuecontains(newEntry))
System.out.println("Do nothing");
else myQueue.add(newEntry);
}

public void moveToBack(T entry)
{
if(myQueuecontains(entry))
myQueue.enque(entry);
else myQueue.add(entry);
}
}

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