What is the ossue with my code?


It gets stuck on the while loop and i cant find any error

Hi @tusharnitharwal

Can you specify which while loop are u talking about?

The while loop in main

at the end of the main function

Can you please specify your logic. You have very much complicated the code without any reason. Also you have not initialised node copy and you are using it. You should try to write very clear logic code.

Actually i want to reverse the given link and then compare the two to check for palindrome. But when i use my reverse function, it alters head so i have initially made a copy of head with the name ‘copy’. Then i run the while loop( which here is causing the problem acc to me) which at each step checks if the data of reversed list (which is temp) and the original list(which is copy) are equal or not. And at each step i updatecopy to copy->next and temp to temp->next until either of them becomes null

@tusharnitharwal
You have not assigned head to copy while declaring copy node. Write node* copy =head.
And then your code should work just fine.
If your query is resolved please mark it as resolved.

hope it helps.

Okay, it worked. Thanks
But what is the problem if i dont assign head to copy?
I had manually updated ‘use’ which is a copy of ‘copy’?
I mean to say that if i dont assign a value to the node at the time of declaration and do node->data= some value, what is the problem with that?

But if copy is not initialised with any, then it might store or might not store any garbage value. And hence can give run error. This is very basic rule.