Question: implement the ArrayBoundedQueue and QueueInterface based on the examples on p. 227 and p. 221. Add or modify any code that you need to. Include
- implement the ArrayBoundedQueue and QueueInterface based on the examples on p. 227 and p. 221. Add or modify any code that you need to. Include methods such as enqueue(), dequeue(), is Full(), isEmpty(), size(), etc. In addition, create a test driver (demo program) based on p. 236, Figure 4.5, and use the sample run illustration as a basis for your test driver. Supply at least 3 test cases (sample runs) based on your test drivers queue operations.
- Include a (brief) analysis of your algorithm and include the pseudo-code.
page221
package ch04.queues;
public interface QueueInterface
{
void enqueue(T element) throws QueueOverflowException1 ;
T dequeue() throws QueueUnderflowException;
boolean isFull();
boolean isEmpty();
int size();}
page227
package ch04.queues;
public class ArrayBoundedQueue
{
protected final int DEFCAP = 100; // default capacity
protected T[] elements; // array that holds queue elements
protected int numElements = 0; // number of elements in the queue
protected int front = 0; // index of front of queue
protected int rear; // index of rear of queue
public ArrayBoundedQueue()
{
elements = (T[]) new Object[DEFCAP]^2 ;
rear = DEFCAP - 1; }
public ArrayBoundedQueue(int maxSize)
{
elements = (T[]) new Object[maxSize]3 ;
rear = maxSize - 1; }
page 236

236 Chapter 4 The Queue ADT What is the name of this test? Sample Test 1 Enter string to enqueue: Test Line 2 enqueue ("Test Line 2") Choose an operation: This is test Sample Test Choose a constructor: 1: ArrayBoundedQueue) 2: ArrayBoundedQueue (int maxSize) 3 isFull() Result: false 1 Choose an operation: Choose an operation: 1: enqueue (element) 2: String dequeue () 3: boolean is Full() 4: boolean isEmpty() 5: int size() 6: stop Testing 2 dequeue () Result: Test Line 1 was returned Choose an operation: isEmpty() Result: true Choose an operation: 2 dequeue() Result: Test Line 2 was returned. Choose an operation: 1 Enter string to enqueue: Test Line 1 enqueue ("Test Line 1") 2 dequeue () Underflow Exception: Dequeue attempted on empty queue. Choose an operation: Choose an operation: isEmpty Result: false 6 End of Interactive Test Driver Choose an operation
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
