Detect if Linked List is Palindrome

Home / Uncategorized / Detect if Linked List is Palindrome

Question:
When i try to put values in a vector while traversing a linked list they remain to be zero and not updating to correct values.Please help!!
bool isPalindrome(Node *head)
{
if(head==NULL ||head->next==NULL)
{
return true;
}
Node*trav=head;
vectorres;
while(trav!=NULL)
{
res.push_back(trav->data);
// cout<data<<" "; trav=trav->next;
}
vector::iterator it1;
/*for(it1=res.begin();it1!=res.end();it1++)
{
cout<::iterator it=res.begin();
head=reverse(head);
Node*trav1=head;
while(trav1!=NULL&& it!=res.end())
{
cout<data<<" "<data!=res[*it])
{
return false;
}
it++;
trav1=trav1->next;
}
return true;
}


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *