Question: Arrays Buffers with and Without Duplicates This assignment assumes you have a mastered assignment 1. If you remember, the ArrayBuffer class in Assignment 1 had
Arrays Buffers with and Without Duplicates This assignment assumes you have a mastered assignment 1. 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 children classes of the ArrayBuffer class. As the name implies, the first class does not allow the insertion of duplicate 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. Use the Java code below to answer the questions: class BufferArray{ // declaration of variables private int numberOfElements=0; private final int BUFFER_SIZE = 20; private int[] intArray = new int[BUFFER_SIZE]; // insert function public boolean insert(int value){ if (numberOfElements==(BUFFER_SIZE-1)) return false; intArray[numberOfElements] = value; numberOfElements += 1; return true; } // display function public void display(){ for(int i=0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
