Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment, we will create two variants of the BufferArray class; BufferArrayNoDups and BufferArrayWithDups. As the name implies, the first class does not allow
In this assignment, we will create two variants of the BufferArray class; BufferArrayNoDups and BufferArrayWithDups. 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 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 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 BUFFERSZ constant, and instead have the init take an integer argument for the size.
If possible implement these two new classes as child classes of the BufferArray class.
Sorted Array Buffers with and Without Duplicates
In this assignment, we will also create two variants of the classes from Assignment ; SortedBufferArrayNoDups and SortedBufferArrayWithDups. As the name implies, the first class is a sorted array and does not allow the insertion of duplicate values, while the second one does. The SortedBufferArrayNoDups class should look like the BufferArrayNoDups class from above. Only the insert operation has to change. Insert has to insert in order. Here there is only one remove function which is stableRemove that has to be slightly altered so that you dont have to go until the end of the array to find the integer. You can stop when you have reached a value greater than the value being passed in For example if your array contains integers and you are asked to remove integer you can stop once you reach as you know cannot be found now. Change locationOf to reflect the fact that the array is sorted.
The SortedBufferArrayWithDups class should also look like the class in SortedBufferArrayWithNoDups class in previous section. This time, change the insert function that allows duplicates but needed to be inserted in order. Now implement the findAll 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 stableRemoveAll function should remove all copies of the target value. Have the stableRemoveAll function return an int with the number of values that were actually removed.
Here findAll and stableRemoveAll become easier. For findAll once you find the first one you need to look at the next element. If its the same keep going until you find an element which is a greater value and you stop searching. And Similarly for stableRemoveAll as you know the number of occurrences and now if you find the locationOf the first one you can stop looking and remove starting from that index to the number of occurrences. So for example if you have an integer array and you are asked to remove location of first is and number of occurrences for is So you need to remove from index to occurrences For this assignment, like the non sorted BufferArray have the init take an integer argument for the size and do not use a default.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started