Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Data Structure Add the following methods to the ArrayBoundedQueue class, and create a test driver for each to show that they work correctly. In

Java Data Structure
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Add the following methods to the ArrayBoundedQueue class, and create a test driver for each to show that they work correctly. In order to practice your array coding skills, code each of these methods by accessing the internal variables of the ArrayBoundedQueue, not by calling the previously defined public methods of the class. 1. String toString()creates and returns a string that correctly represents the current queue. Such a method could phove useful for testing and debugging the class and for testing and debugging applications that use the class. Assume each queued element already provides its own reasonable tostring method. 2. int space()returns an integer indicating how many empty spaces remain in the queue. 3. void remove(int count)removes the front count elements from the queue, and throws QueueUnderflowException if there are less than count elements in the queue. 4. boolean swapStart()returns false if there are less than two elements in the queue; otherwise it reverses the order of the front two elements in the queue and returns true. 5. boolean swapEnds() returns false if there are less than two elements in the queue; package ch04.queues: t protected final int DEFCAP =100;/1 default capacity protected T[] elements; / array that holds queue elements protected int origcap; /f original capacity protected int numBlements =0; // number of elements in this queue protected int front =0; index of front of queue protected int rear; /1 index of rear of queue pub11c ArrayUnboundedpueue () ( elements =(I[]) now object [DEFCAP] rear = DEECAP 1; origCap = DEFCAP; 1 publie ArrayUnboundedgueue (1nt origCap) t elements =([1) new object[oxigcap]; rear = origCap 1; this . origcap = origcapi 1 1 T toReturn = elements[front]; elements [front] = nuli; front =(front+1) o elements. length; numslements = numElements -1 ; return toReturn; ) 1 public boolean isErgty () II Returns true if this queue is empty; otherwise, returns false. 1 return (numilements =0); 3 public boolean isfull.() If Returns false - an unbounded queue is never full. f return false; 3 public int size() 1/ Returns the number of elements in this queue. 1 return numslements; 3

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions