Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

. If you remember, the ArrayBuffer class in Assignment 1 had methods for insert, find, remove, removeStable, and display, as well as a private helper

. If you remember, the ArrayBuffer class in Assignment 1 had methods for insert, find, remove, removeStable, and display, as well as a private helper function called locationOf.

In this assignment, we will create two variants of the ArrayBuffer class; ArrayBufferNoDups and ArrayBufferWithDups. As the name implies, the first class does not allow the insertion of dublicate values, while the second one does. The ArrayBufferNoDups class should look like the ArrayBuffer class in Assignment 1. Only the insert operation has to change. Both remove functions should assume that there is never more than one copy of a value. For this assignment I would also like the distinction between the two remove functions to be more clear. So please rename them fastRemove and stableRemove.

The ArrayBufferWithDups class should also look like the class in ArrayBuffer class in Assignment 1. This time, do not change the insert function, and implement both remove functions as for the NoDups case. But, in addition, add three new methods, called findAll, fastRemoveAll, and stableRemoveAll. The findAll function should return an int with the number of elements that have the same value as the target value, while the two removeAll functions should remove all copies of the target value. Have both removeAll functions return an int with the number of values that were actually removed. For this assignment, we will make two more changes. First, omit the BUFFER_SZ constant, and instead have the constructor take an integer argument for the size.

Asg 1:

#include using namespace std; class BufferArray { private: const int BUFFER_SIZE; int numberOfElements, *intArray; public: BufferArray() : BUFFER_SIZE(8), intArray(new int[BUFFER_SIZE]),numberOfElements(0) {} bool insert(int value) { if(numberOfElements < BUFFER_SIZE) { intArray[numberOfElements++] = value; return true; } else return false; } bool remove(int value) { int index = locationOf(value); if(index != -1) { intArray[index] = intArray[numberOfElements - 1]; numberOfElements--; return true; } else return false; } bool find(int target) { if(locationOf(target) != -1) return true; else return false; } void display() { for(int i = 0; i < numberOfElements; i++) { if(i == numberOfElements - 1) cout<                        

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

=+ Should the MNE belong (why, why not)?

Answered: 1 week ago

Question

=+ What is the role of government in bargaining?

Answered: 1 week ago