Plzz rectify my code


please tell the necessary changes needed

Hello @Bhavit_Singla,

The fast and slow pointers would not work in the linked you have created.
Reason:
The linked list is linear. There is no actual cycle in the linked list.

Solution:

  1. Either you can check for the element after which elements starts repeating in your linear linked list and remove the loop.

  2. You can create a loop while inserting elements in your linked list and then apply the logic of two pointers to detect and remove the loop.
    You can refer to this code i have corrected earlier:
    https://ide.codingblocks.com/s/161841 2

Hope, this would help.
Give a like if you are satisfied.

https://ide.codingblocks.com/s/161841 sir could you please tell what you have done in buildcycle function i am not able to get it could you explain step by step

please tell line number 53 of this code https://ide.codingblocks.com/s/161841

Hello @Bhavit_Singla,

  1. I have checked if the value starts repeating then i am creating a loop by pointing it to the node whose value has repeated.

  2. while(temp->next!=head){
    This is a normal statement to iterate over the list with last node pointing to head.
    As you have created in the push() function.

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.