I need write a function that goes through a linked list and see if the words in the list are palindromes. So, I need to go through the letters in the word one way and compare that with going through the letters of the word the opposite way and if they match then the word is a palindrome and I return true.
This function takes the head and the tail of the doubly linked list and returns true if the string is a palindrome, false otherwise.
You have the head and the tail of the list (I suppose the list values are chars?) -
just go this way:
1) if head and tail are the same element, it's a palindrome
2)otherwise:
2.1)is tail the predecessor of head?
2.1.1) if yes, it is a palindrome
2.1.2) if no, are the values of head and tail the same?
2.1.2.1) if yes, set head to head->next and tail to tail->prev, and then go back to 1
2.1.2.2) if no, it is not a palindrome.
just try to do this on paper, and you will see how it works.