Can u please tell me where I am going wrong.
Failing in 2 test cases
Please solve my issue.
Your code is not working correctly for following test case as,
4
1 2 2 1
Expected output : true
Your output : false
You can use the following approach as ,
int palindrome(node *head)
{
int flag=1;
int count=getcount(head);
node *middle=findmidpoint(head); // finding midpoint of linked list
middle=reverse(middle); // rfeverse the linked list from middle element
int step=0;
while(step<(count/2))
{
step++;
if(head->data!=middle->data)
{
flag=0;
}
else
{
head=head->next;
middle=middle->next;
}
}
return flag;
}