Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++ programming) 1) Create a class thatimplements a double-ended queue as described in Moodle. This class should be implemented using an array as the underlying

(C++ programming)

1) Create a class thatimplements a double-ended queue as described in Moodle. This class should be implemented using an array as the underlying data structure. Your default constructor should create an array of 100 elements and you should have a overloaded constructor with a parameter for the array size. This class should have methods for:

addLeft, addRight, getLeft, getRight, isEmpty, and isFull.

The double-ended queue should wrap on the array. That is, you do not move any items already in the array, just increment and decrement the markers for right and left.

If asked to add when full, you should create a new array twice as large and copy the existing elements to it and when asked to get an item when empty, you should throw an exception.

Note, you should not initialize the underlying array to NULL or zero or any other value.

2) Add a new method to the double-ended queue thatlists the elements. The first element displayed should be at the getLeft position and the last one at the getRight position. Do not just print out the underlying array. Do not print any locations in the array that do not have valid values.

This method should return a string that can be displayed in the calling program. If the queue is empty, you should return a string containing the message Queue is empty. Name this method listLeftRight.

3) Create a stack class based off your double-ended queue. It should support push, pop, and peek. Push adds an item to the stack, peek shows the last item added, and pop removes and returns the last item added.

This should be implemented using aggregation of classes, that is, you should have an object of type double-ended queue in your stack class that you use to implement the required functions. If the underlying method throws an exception, you should also throw one.

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

More Books

Students also viewed these Databases questions

Question

| Whom can I trust to help me make sure that I am living my values?

Answered: 1 week ago

Question

1. How do most insects respire ?

Answered: 1 week ago