Singly Linked List Lab
Create a Program to Check whether a Singly Linked List is a Palindrome
This is a Python program to check whether a singly linked list is a palindrome.
Problem Description
The program creates a linked list using data items input from the user and determines whether it is a palindrome.
Problem Solution
- Create a class Node with instance variables data and next.
- Create a class LinkedList with instance variables head and last_node.
- The variable head points to the first element in the linked list while last_node points to the last.
- Define methods append and display inside the class LinkedList to append data and display the linked list respectively.
- Define method get_prev_node which takes a reference node as argument and returns the node before it.
- Define a function is_palindrome which returns True if the linked list passed to it is a palindrome.
- The function is_palindrome iterates through the linked list from the start and the last node towards the middle to check if the list is a palindrome.
- Create an instance of LinkedList, append data to it and determine whether it is a palindrome.
Please submit your work before continuing