C Program To Check If A Linked List Of Strings Forms A Palindrome Last Updated : 22 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Given a linked list handling string data, check to see whether data is palindrome or not? Examples: Input: a -> bc -> d -> dcb -> a -> NULL Output: True String "abcddcba" is palindrome. Input: 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. C++ // Program to check if a given linked list // of strings form a palindrome #include <bits/stdc++.h> using namespace std; // Link list node struct Node { string data; Node* next; }; // A utility function to check if str // is palindrome or not bool isPalindromeUtil(string str) { int length = str.length(); // Match characters from beginning // and end. for (int i = 0; i < length / 2; i++) if (str[i] != str[length - i - 1]) return false; return true; } // Returns true if string formed by linked // list is palindrome bool isPalindrome(Node *node) { // Append all nodes to form a string string str = ""; while (node != NULL) { str.append(node->data); node = node->next; } // Check if the formed string is // palindrome return isPalindromeUtil(str); } // A utility function to print a given // linked list void printList(Node *node) { while (node != NULL) { cout << node->data << " -> "; node = node->next; } printf("NULL"); } /* 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 code 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"): printf("false"); return 0; } Output: true Time Complexity: O(n), where n is the number of nodes in the given linked list.Auxiliary Space: O(m), where m is the length of the string formed by the linked list. Please refer complete article on Check if a linked list of strings forms a palindrome for more details! Comment More infoAdvertise with us Next Article C Program To Check If A Linked List Of Strings Forms A Palindrome kartik Follow Improve Article Tags : Linked List C Programs DSA palindrome Practice Tags : Linked Listpalindrome Similar Reads C Program To Check If A Singly Linked List Is Palindrome Given a singly linked list of characters, write a function that returns true if the given list is a palindrome, else false. Recommended: Please solve it on "PRACTICE" first, before moving on to the solution. METHOD 1 (By reversing the list): This method takes O(n) time and O(1) extra space. 1) Get t 7 min read C Program to Check for Palindrome String A string is said to be palindrome if the reverse of the string is the same as the string. In this article, we will learn how to check whether the given string is palindrome or not using C program.The simplest method to check for palindrome string is to reverse the given string and store it in a temp 4 min read TCP Client-Server Program to Check if a Given String is Palindrome Prerequisites: Socket Programming in C/C++, TCP and UDP server using select, UDP Server-Client implementation in C TCP Client-Server Implementation in C This article describes a Client and Server setup where a Client connects, sends a string to the server and the server shows the original string and 4 min read Check whether the given string is Palindrome using Stack Given a string s, the task is to determine whether the given string is a palindrome or not by utilizing a stack. A palindrome is a string that reads the same forwards and backwards.Examples:Input: s = "geeksforgeeks"Output: NoExplanation: Reversing "geeksforgeeks" using a stack results in "skeegrofs 10 min read Palindrome Number Program in C Palindrome numbers are those numbers that remain the same even after reversing the order of their digits. In this article, we will learn how to check whether the given number is a palindrome number using C program.ExamplesInput: 121Output: YesExplanation: The number 121 remains the same when its dig 3 min read Java Program To Check If A Linked List Of Strings Forms A Palindrome Given a linked list handling string data, check to see whether data is palindrome or not? Examples: Input: a -> bc -> d -> dcb -> a -> NULL Output: True String "abcddcba" is palindrome. Input: a -> bc -> d -> ba -> NULL Output: False String "abcdba" is not palindrome. Reco 2 min read Python Program To Check If A Linked List Of Strings Forms A Palindrome Given a linked list handling string data, check to see whether data is palindrome or not? Examples: Input: a -> bc -> d -> dcb -> a -> NULL Output: True String "abcddcba" is palindrome. Input: a -> bc -> d -> ba -> NULL Output: False String "abcdba" is not palindrome. Reco 2 min read Check if a linked list of strings forms a palindrome 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 palindro 6 min read C++ Program To Check If A Singly Linked List Is Palindrome Given a singly linked list of characters, write a function that returns true if the given list is a palindrome, else false. Recommended: Please solve it on "PRACTICE" first, before moving on to the solution. METHOD 1 (Use a Stack): A simple solution is to use a stack of list nodes. This mainly invol 9 min read Python Program To Check If A Singly Linked List Is Palindrome Given a singly linked list of characters, write a function that returns true if the given list is a palindrome, else false. Recommended: Please solve it on "PRACTICE" first, before moving on to the solution. METHOD 1 (Use a Stack): A simple solution is to use a stack of list nodes. This mainly invol 6 min read Like