Write a member function named filter
that could be added to the ArrayIntList
class.
Your function should accept a reference to a Set of integers as its parameter and should remove from your list any integers that appear in the set.
Suppose an ArrayIntList
variable named list
stores the following values:
{3, 14, 5, -1, 7, 14, 7, 7, 29, 3, 7}
And suppose we create a set of integers called set that stores {3, 5, 7}
.
The call of list.filter(set);
would change the list to store the following sequence of four values:
{14, -1, 14, 29}
If the set passed is empty, or if none of its values occur in your list, then the list is unchanged by your function.
You should return a result of true
if the list is modified and false
if it is not modified by the call.
Constraints:
You may call other private member functions of the ArrayIntList
if you like, but not public ones.
Do not make assumptions about how many elements are in the list or about the list's capacity.
Do not use any auxiliary data structures to solve this problem (no array, vector, stack, queue, string, etc).
Your function should not modify the state of the set that is passed in; its header should be declared in such a way as to promise this to the client.
Your solution must run in O(N2) time or better, where N is the number of elements in the list.
Write the member function as it would appear in ArrayIntList.cpp
.
You do not need to declare the function header that would appear in ArrayIntList.h
.
Assume that you are adding this method to the ArrayIntList
class as defined below:
class ArrayIntList {
private:
int* elements; // array storing element data
int mysize; // number of elements in the array
int capacity; // array's length
public:
...
};