I have to create a remove method which will remove all elements equal to the obj
ID: 3553852 • Letter: I
Question
I have to create a remove method which will remove all elements equal to the object called from the method. Here is what i have so far. the find method gors through the list and finds the Node with element as its information then sets location to that Node and previous to the Node before location
public int removeAll(Object element)
//removes all objects from list equal to element.
{
int numElems = 0;
this.find(element);//searches for Node with info = element
while(found != false)
{
location = location.getLink();
numElems++;
this.find(element);
}
return numElems;
}
Explanation / Answer
public int removeAll(Object element) //removes all objects from list equal to element. { int numElems = 0; int found = this.find(element);//searches for Node with info = element while(found != false) { previous.link=location.getlink(); numElems++; this.find(element); } return numElems; }