Write a c program to check whether given link list is palindrome?  Each node of a linked list represents a number in it. From the below figure it is clear that the linked list 1->2->3->2->1 is a palindrome.

## How to check whether given link list is palindrome

There are various methods to check palindrome. The question is asked in the interview, so it is better to write less complexity based code. Lets discuss each method and its advantages.

## (1) Recursive method: Time complexity O(n)

```#include<stdio.h>
#include <stdlib.h>

#define true 1
#define false 0
{
int a;

void append (int a);
{

{
free(tmp);
}

}
int main ()
{
append (1);
append (2);
append (3);
append (2);
append (1);

else

return 0;
}

void append (int a)
{
// if empty
{
}
else
{
// go to last node
while (tmp->next != NULL)
tmp = tmp->next;

// append data
p->a = a;
tmp->next = p;
p->next = NULL;
}
}

{
// base terminatig condition for recursion
if (pp == NULL)
return true;

// call checkforpalindrome
/* calling on next node, make pp->next on stack */
checkforpalindrome (pp->next);

/* now pp will point to last node */
/* compare last node to first node */
int flag = false;
{
flag = true;
}
else
{
flag = false;
}

return flag;
}```