pydatastructs
pydatastructs copied to clipboard
Add `is_palindrome` method to LinkedList class
What's this PR about?
This PR adds a new method is_palindrome to the LinkedList class to check if a linked list is a palindrome. The method works for all types of linked lists: SinglyLinkedList, DoublyLinkedList, SinglyCircularLinkedList, and DoublyCircularLinkedList.
What changes were made?
-
New Method:
- Added
is_palindrometo theLinkedListclass. - The method traverses the linked list, stores elements in a temporary array, and checks if the array is equal to its reverse.
- Added
-
Tests:
- Added comprehensive test cases for
is_palindromein the test file. - Verified functionality for all linked list types.
- Added comprehensive test cases for
Fixes: #656
is_palindroneis applicable to any linear data structure right? So let's add it inlinear_data_structures/algorithms.py. Keep the method here and call it inis_palindroneinalgorithms.pyfile. Also implementis_palindronemethod inOneDimensionalArray,DynamicOneDimensionalArray.
@czgdp1807 So do you want to keep the method here and also add is_palidrome method in OneDimensionalArray and DynamicOneDimensionalArray. And call them in algorithms.py ?