Possible Duplicate:
Single Linked List is Palindrome or not
Suppose i have a link list having a char item,i need to find if the characters in that link list is a palindrome or not. I know link list not at all a suitable structure for this, but then if we have one what to do?
eg a-b-c-b-a
a doubly link list is easy,we can start of with the head and tail
ptrh=head ptrt=tail
if(ptrh->item==ptrt->item)
and
ptrh->ptrh->frwdlink
ptrt->ptrt->bcklink
But what if we have a single linked list? How to implement it then?
Knowing the size of the list you can tell what the middle is. Then as you go through you just cache all the chars up to the middle and make sure they appear in reverse order after the middle.