For the linked list insertion program, i got a question.
public void printList() {
if (isEmpty()) {
System.out.println(“List is Empty!”);
return;
}
Node temp = headNode;
System.out.print("List : ");
while (temp.nextNode != null) {
System.out.print(temp.data.toString() + " -> ");
temp = temp.nextNode;
}
System.out.println(temp.data.toString() + " -> null");
}
for the above piece of code, when the linked list have only element, so the nextNode will be null.
So, the printList() method will not print any elements even though linked list is not empty.
can anyone confirm.??