This document discusses two variants of the BufferArray class: BufferArrayNoDups, which does not allow duplicate values, and BufferArrayWithDups, which does. BufferArrayNoDups only needs to change the insert operation to prevent duplicates, while BufferArrayWithDups implements additional methods like findAll, fastRemoveAll, and stableRemoveAll to handle duplicates. The constructor is also changed to take the buffer size as a parameter instead of using a constant.
Array Buffers with and Without Duplicates This assignment as.pdf
1. Array Buffers with and Without Duplicates
This assignment assumes you have a mastered assignment the BufferArray class in Assignment 1
had
methods for insert, find, remove, stableRemove, and display, as well as a private helper function
called locationOf. Change the remove function as fastRemove
In this assignment, we will create two variants of the BufferArray class; BufferArrayNoDups and
BufferArrayWithDups as children classes of the BufferArray class. As the name implies, the first
class
does not allow the insertion of duplicate values, while the second one does. The
BufferArrayNoDups
class should look like the BufferArray 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 the remove as fastRemove and leave the other one with the same name
stableRemove.
The BufferArrayWithDups class should also look like the class in BufferArray 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.