Pls explain why I am getting a run error ,Not only this but most of problems I have been solving in Linked Lists I am Getting a Segmentation fault/Run error .How can I avoid it and be careful?
The approach is little bit incorrect… Use the following function for the palindrome :
bool palindrome(node *head,int n)
{
int flag=1;
int count=n;
node*temp=midPoint(head); // determine the midpoint in linked list
temp=reverse(temp); //Reverse the list from mid point
int step=0;
while(step<(count/2))
{
step++;
if(head->data!=temp->data)
{
flag=0;
}
else
{
head=head->next;
temp=temp->next;
}
}
return flag;
}