We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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 :-) !
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Insert a Node at the Tail of a Linked List
You are viewing a single comment's thread. Return to all 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 :-) !