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

As you may recall, the implementation of the cs20::Queue< Object > data structur

ID: 3846910 • Letter: A

Question

As you may recall, the implementation of the cs20::Queue< Object > data structure presented in class used a linked node structure with an identified front and back node. Based on this data structure, write the following method:

template <class Object>
bool Queue<Object>::separatedBy( Object a, Object b, int amount ) const;

This method should determine whether the Queue has the two specified object arguments separated by the desired amount of QueueNodes. Feel free to define any public or private methods or members on the class Queue<Object> as you need. Please work with the code from class.

For example, please consider the queue shown below:


separatedBy( 8, 20, 1 ) should return false because 8 and 20 are not found on the queue.
separatedBy( 12, 20, 1 ) should return false because 20 is not found on the queue.
separatedBy( 12, 1, 1 ) should return false because 12 and 1 are not separated by 1 QueueNode on the queue.
separatedBy( 12, 1, 3 ) should return true because 12 and 1 are separated by 3 QueueNodes (namely, 5, 7, and 13) on the queue.

code is provided here

https://dropfile.to/QevBJfK access key; 2vs7ny6
https://dropfile.to/W7VaG8c access key:   FaQ5K9G

Explanation / Answer

Code:

import java.util.*;

public class easyQueue

{

private LinkedList queue;

public easyQueue( )

{

queue=new LinkedList();

}

public boolean isEmpty()

{

if(queue.isEmpty())

return true;

else

return false;

}

public void enQueue(Object i)

{

queue.addLast(i);

}

public Object deQueue()

{

if (queue.isEmpty())

{

System.out.println("Queue is empty!");

return null;

}

else

{

Object result=queue.getFirst();

queue.removeFirst();

return result;

}

}

public void printQueue()

{

System.out.println("the Queue is: " + queue);

}

public static void main( String [ ] args )

{

easyQueue Q = new easyQueue();

Object x; int i; Q.printQueue();

for( i = 0; i < 5; i++ )

{

System.out.print("Enqueued " + i + ". Here is ");

Q.enQueue( new Integer( i )); Q.printQueue();

}

System.out.println( "do some dequeues..." );

while(!Q.isEmpty())

{

x = Q.deQueue(); System.out.print( "Dequeued " +(Integer)x +". Here is ");

Q.printQueue();

}

Q.deQueue();

}

}

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