pydatastructs icon indicating copy to clipboard operation
pydatastructs copied to clipboard

Add `is_palindrome` method to LinkedList class

Open asmit27rai opened this issue 8 months ago • 1 comments

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?

  1. New Method:

    • Added is_palindrome to the LinkedList class.
    • The method traverses the linked list, stores elements in a temporary array, and checks if the array is equal to its reverse.
  2. Tests:

    • Added comprehensive test cases for is_palindrome in the test file.
    • Verified functionality for all linked list types.

Fixes: #656

asmit27rai avatar Mar 18 '25 21:03 asmit27rai

is_palindrone is applicable to any linear data structure right? So let's add it in linear_data_structures/algorithms.py. Keep the method here and call it in is_palindrone in algorithms.py file. Also implement is_palindrone method in OneDimensionalArray, 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 ?

asmit27rai avatar Mar 19 '25 08:03 asmit27rai