Palindrome LinkedList Recursive

Details

Send the pointer to head(phead) and head itself.
Recurse till next of head is not NULL.
Start popping the frames. If *phead == *head, good to move to next frame-up.
Before moving up, move phead to next

// Recursive function to check if linked list is palindrome or not
int checkPalindrome(struct Node** left, struct Node* right)
{
	// base case
	if (right == NULL)
		return 1;

	int res = checkPalindrome(left, right->next) &&
			((*left)->data == right->data);
	(*left) = (*left)->next;

	return res;
}

Reference


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.