Why doesn’t this code create a Linked List?

You are not changing pointer for head for initial case and head is always null.

if(cur==null){
   cur = nn;
}

should be

if(head==null){
    head = nn;
}

Leave a Comment