assume you are in main.cpp define a function that is NOT SCOPED to any class. It is NOT a member of the ListInterface nor LinkedList classes. Your function should accept two lists. You will remove all values from the first list that are present in the second list. Example:
Lists before call: Lists after call:
target: A, B, C, A, D, C, E, F, B, C, A target: A, A, D, E, F, A
toRemove: C, B, Q, Z toRemove: C, B, Q, Z
template <typename T> void removeHelper(ListInterface<T>& target, const ListInterface<T>& toRemove) { //your code below |
template <typename T>
void removeHelper(ListInterface<T>& target, const
ListInterface<T>& toRemove) {
for(int i=1;i<target.length();++i)
{
//get each entry from target and compare with toRemove
entries
for(int j=1;j<toRemove.length();++j)
{
//if entry at index i is equal to entry at index
j
if(target.getEntry(i)==toRemove.getEntry(j))
{
target.remove(i); //remove
entry at index i from target
break;
}
}
}
}
Get Answers For Free
Most questions answered within 1 hours.