Error in the code


what is wrong in this code?

Hey
So basically your while loop is running infinitely
one way to control it is as follows:-
You know that this loop has to run n times where n is the length of the linked list. so you can maintain a counter starting from 0, and break the loop as soon as counter becomes n(i.e. n iterations get complete). This is one possible solution and your code will work fine by doing this. Edited code is:-

Also, you can find what else you can change in the loop if you choose not to use this counter thing, by using a test case to dry run your code.
Sorry for the late reply though!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.