I came across the following problem:
Delete a node in the middle of a singly linked list, given only access to that node. (head is not given) Now there are a lot of solutions and they all do not work when the element to be deleted is the last node.
Why wouldn't this work?
public static void removeNode (Node n){
if(n.next == null){ //n is the last node
n= null;
return;
}
//handling general case here
}