Insert a Node at the Tail of a Linked List

  • + 0 comments

    When you exit the while loop you have a pointer pointing to nowhere. It didn't matter on the Print exercise, but here it does.

    In your else statement, create another Node* pointer variable (*tail, for instance), and make it receive your *p at each iteration.

    At the last iteration, it will be pointing to the last Node structure, which will be the tail of the linked list. Then your p->next=temp; will work :-) !