Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

Students also viewed these Databases questions