# Check if a linked list of strings forms a palindrome

• Difficulty Level : Easy
• Last Updated : 01 Dec, 2020

Given a linked list handling string data, check to see whether data is palindrome or not?
For example,

Input  : a -> bc -> d -> dcb -> a -> NULL
Output : True
String "abcddcba" is palindrome.

Output : a -> bc -> d -> ba -> NULL
Output : False
String "abcdba" is not palindrome.

## Recommended: Please solve it on “PRACTICE” first, before moving on to the solution.

The idea is very simple. Construct a string out of given linked list and check if the constructed string is palindrome or not.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.

## C/C++

 // Program to check if a given linked list of strings// form a palindrome#include using namespace std;  /* Link list node */struct Node{    string data;    Node* next;};  // A utility function to check if str is palindrome// or notbool isPalindromeUtil(string str){    int length = str.length();      // Match characters from beginning and    // end.    for (int i=0; idata);        node = node->next;    }      // Check if the formed string is palindrome    return isPalindromeUtil(str);}  // A utility function to print a given linked listvoid printList(Node *node){    while (node != NULL)    {        cout << node->data << " -> ";        node = node->next;    }    printf("NULL\n");}  /* Function to create a new node with given data */Node *newNode(const char *str){    Node *new_node = new Node;    new_node->data = str;    new_node->next = NULL;    return new_node;}  /* Driver program to test above function*/int main(){    Node *head = newNode("a");    head->next = newNode("bc");    head->next->next = newNode("d");    head->next->next->next = newNode("dcb");    head->next->next->next->next = newNode("a");      isPalindrome(head)? printf("true\n"):                        printf("false\n");      return 0;}

## Java

 // Java Program to check if a given linked list of strings// form a palindrome  import java.util.Scanner;  // Linked List nodeclass Node{    String data;    Node next;      Node(String d)    {        data = d;        next = null;    }}  class LinkedList_Palindrome{    Node head;      // A utility function to check if str is palindrome    // or not    boolean isPalidromeUtil(String str)    {        int length = str.length();          // Match characters from beginning and        // end.        for (int i=0; i

## C#

Output:
true

My Personal Notes arrow_drop_up