Question
these are the given information and I'm struggling with remove public class Queue { public int size; public String[] items; /** * initialize array to
these are the given information and I'm struggling with remove
public class Queue {
public int size;
public String[] items;
/**
* initialize array to an empty array and size to 0
*/
public Queue() {
size = 0;
items = new String[0];
}
/**
*
* @return the front item (and remove it) from the queue.
* return null if queue is empty.
*/
public String remove() {
code here
return ;
}
@@ test
class QueueTest {
Queue q1, q2, q3;
@BeforeEach
public void run() {
q1 = new Queue();
q2 = new Queue();
q3 = new Queue();
for(int i=0; i < 100; i++) {
q2.insert((i+1)+"");
}
for(int i=0; i < 1000; i++) {
q3.insert((i+1)*2+"");
}
}
public void testRemove() {
assertNull(q1.remove());
for(int i=0; i < 100; i++) {
String str = q2.remove();
assertNotNull(str);
assertEquals((i+1)+"", str);
}
assertNull(q2.remove());
for(int i=0; i < 1000; i++) {
String str = q3.remove();
assertNotNull(str);
assertEquals((i+1)*2+"", str);
}
assertNull(q3.remove());
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started