link.removeFirstOccurrence(new Integer(9));
This is what my professor wants, but it only works when I pass values in like link.removeFirstOccurrence(9);
. Any advice?
public boolean removeFirstOccurrence(Object obj) {
DNode<E> current = head;
DNode<E> temp = null;
if(current != null && current.data == obj) {
head = current.next;
return true;
}
while(current != null && current.data != obj) {
temp = current;
current = current.next;
}
if(current == null) {
return false;
}
temp.next = current.next;
current.next.previous = current.previous;
return true;
}