Question: I need help with the following steps: 1. Modify 'MyQueue.java' so that it doubles up the size of array if it is full when attempting

I need help with the following steps:

1. Modify 'MyQueue.java' so that it doubles up the size of array if it is full when attempting enqueue() and enqueues the given 'val'. Another modification is to get rid of variable 'rear'. You can live without it by using 'front' and 'numElements'.

2. Modify 'MyQueueLL.java ' to add your implementation of 'dequeue()'. Be careful of special conditions such as dequeue() when it is empty or dequeue() when it has only one element.

----------------------------------------------------------------------------------------------------------------------------------------------------------

package apps; public class MyQueueLL { SLLNode front; SLLNode rear; int numElements; public MyQueueLL() { front = null; rear = null; numElements = 0; } public void printQueue() { System.out.printf("printQueue(%d): ", numElements); SLLNode curNode = front; while (curNode != null) { System.out.print(curNode.info + " "); curNode = curNode.next; } System.out.println(); } public void enqueue(T val) { SLLNode newNode = new SLLNode(val); if (rear == null) { front = newNode; } else { rear.next = newNode; } rear = newNode; numElements++; } public T dequeue() { // need more work numElements--; } public boolean isFull() { return false; } public boolean isEmpty() { return front == null;} }

----------------------------------------------------

package apps; public class MyQueue { T[] elements; int front; int rear; int numElements; public MyQueue() { elements = (T[]) new Object[5]; front = 0; rear = -1; numElements = 0; } public void printArray() { System.out.print("printArray(): "); for(int i=0;i                                            

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!