I am trying to traverse a doubly linked linked list but i seem to get an infinite loop. My goal is to find the first left most occurrence of an element in the list. I find the element but my program seems to keep looping. The only way to stop it from looping is breaking. There has to be another way. Thanks. {
Node<E> temp;
temp = head;
while(temp.next != null){
if(temp.value==obj){
System.out.println("YES");
}
else{
temp = temp.next;
}
System.out.println("\nNO");
}
}
break;in your if condition. If the value is found it won't come out of the loop and never reach that else statement.