what is wrong in this code?
Palindrome using linked lists
Eshanika, your code is not producing anything, plz create a node class, since you havent created any in the code you send.
sorry this is the code i m getting wrong anwer
Your code is not producing correct answer for following test case:
4
1 2 2 1
Your output : False
Expected output : True
Use this kind of logic in your code :
node *middle=findmidpoint(head);
middle=reverse(middle);
int step=0;
while(step<(count/2))
{
step++;
if(head->data!=middle->data)
{
flag=0;
}
else
{
head=head->next;
middle=middle->next;
}
}
Make separate functions for reverse and midpoint and also counting no of nodes in linked list…
1 Like