-
Notifications
You must be signed in to change notification settings - Fork 20.1k
Closed
Labels
Description
There should be an else clause on delete(Node n, int key) method for the case where the n.getNext() node does not have the getKey()==key.
/**
Linked list class - delete method with the following signature
*/
private void delete(Node n, int key) {
if (n.getNext().getKey() == key) {
if (n.getNext().getNext() == null) {
n.setNext(null);
} else {
n.setNext(n.getNext().getNext());
}
}
}
Possible Solution
private void delete(Node n, int key) {
if (n.getNext().getKey() == key) {
if (n.getNext().getNext() == null) {
n.setNext(null);
} else {
n.setNext(n.getNext().getNext());
}
}
else{
delete(n.getNext(),key);
}
}
siriak