+ 3
want help
what is the error and how i fix this its running infinite https://code.sololearn.com/cTIk83t8Ccht/?ref=app
1 Respuesta
+ 4
On line 52 and 53
head=q;
p=head;
You are detaching both *head* and *p*(which looking at your code holds address of head) to the new node created inside the loop i.e. *q*, Which leaves no pointer pointing to the acctual head of the list.
And after executing next 2 line, your linked list is attached to itself resulting in an infinite loop when trying to print it.
removing line 52 and 53 from your code should fix the issue.
Here is the fix 👇
https://code.sololearn.com/cxqL3jGbm28W/?ref=app