Here’s the code
public void findDNode(String name)
{
DNode u = header;
while(u != null)
{
if(name == u.getElement())
{
System.out.println(u.getElement());
break;
}
else if (u == null)
{
System.out.println("Error: not found");
break;
}
u = u.nextNode();
}
}
For some reason when the node that I am looking for doesn’t exist it’s doesn’t print the error: not found message.
edit: nevermind just realised when u== null the while loop won’t happen
u never becomes null inside the loop! Perform the check after the loop.
Edit: and yes, you should use equals()