|
0
Okay do this. Grab a piece of paper and draw the linked list. Then run through your code. Let's say that your linked list has n elements. If we run the (n-1)th iteration, your while loops check if n is null. It's not so it prints out n-1 and then it advances the pointer to n. Now again, your while loop checks if n+1 is null. It is so it doesn't run that last iteration. You need to be checking if the element itself is null and not the one next to it. |
|
0
If you use temp->next!=NULL,then your print function will terminate before it prints out the last element in your linked list. |