Skip to main content

Check palindrome in given Linked List

There are many ways to check given linked list elements are contains palindrome. We can solve this problem by using of Stack and Recursion are very easily. In this post mentioning both ways to solve this problem solution.

Check palindrome in given Linked List

Method 1: This is a simplest solution of this problem. Create a empty stack and first insert all elements of linked list into an stack. After that comparing the stack top (root) element is equal to linked list node. When it is equals then remove stack top element.

Similar way compare stack top elements to linked list upcoming nodes. If stack and current linked list nodes are not same then in this case linked list are not contain palindrome. Otherwise exist.

Method 2 Recursion is an another way to find palindrome in given linked list. Here given code implementation process.





Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment