Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: You will modify the standard stack and queue so that they do not allow duplicate items and they provide a method to change the

Question: You will modify the standard stack and queue so that they do not allow duplicate items and they provide a method to change the priority of a particular element.

Use an array-based implementation of each data structure.

Part A: Stacks

Implement a new kind of stack that only accepts a single copy of an object in the stack (i.e., it does not allow duplicates).

If an element is pushed onto the stack, and the element already exists in the stack, the stack will remain unchanged.

Your class extends ArrayStack and implements NoDupsPrioritizeStackInterface (provided).

The modified ArrayStack class has protected variables so you can directly access them in NoDupsPrioritizeArrayStack.

Do not make any changes to ArrayStack.

You will write three methods.moveToTop(T) allows you to prioritize an element in the stack.

If invoked with an element currently in the stack, the method moves the element to the top of the stack.

If invoked with an element not in the stack, the method adds the element to the top of the stack (as would normally happen with push).

display() shows the elements of the stack

push(T)

you must override push so that duplicates are not added to the stack

Part B: Queues

Implement a new kind of queue that only accepts a single copy of an object in the queue (i.e., it does not allow duplicates).

If an element is enqueued, and the element already exists in the queue, the queue will remain unchanged.

Your class should implement NoDupsDePrioritizeQueueInterface (provided).

The modified ArrayQueue class has protected variables so you can directly access them in NoDupsDePrioritizeArrayQueue.

Do not make any changes to ArrayQueue.

You will write three methods.moveToBack(T) allows you to de-prioritize an element in the queue.

If invoked with an element currently in the queue, the method moves the element to the back of the queue .

If invoked with an element not in the queue , the method adds the element to the back of the queue (as would normally happen with enqueue).

display() shows the elements of the queue

enqueue(T)

you must override enqueue so that duplicates are not added to the queue

Notes for Part A and Part B:

Only modify the two new classes- do not change any other classes or interfaces.

Start by reviewing the provided ArrayStack/ArrayQueue classes.

Make sure you have a strong understanding of how these original classes are implemented.

Both classes use expandable arrays as the underlying data structure.

The ArrayStack class stores the bottom of the stack in the 0 position.

The ArrayQueue class uses a circular array with one unused location. The front index changes with dequeues and the back index changes with enqueues.

Access the underlying array directly. Do not destroy/rebuild the stack/queue each time you need to look at/examine its entries!

Make your solution efficient by considering the front/back/top indexes. Don't examine positions if it's not necessary to do so.

Reuse code when possible.

Think about special cases (like empty and singleton stacks and queues).

I have provided two driver programs to test your code.

I recommend that you run additional tests to make sure your classes function correctly when the number of elements approaches capacity.

Here is a link to the homework files: https://drive.google.com/drive/folders/1-Hi_sO4UKBD6Mnb2z_nHDMUdVRrG0f5E

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

Students also viewed these Databases questions

Question

Q) Summary on "how does the primary market for securities operate"?

Answered: 1 week ago