Palindrome Test case

link: https://github.com/kush1912/Data-Structures-and-Algorithms-in-C-/blob/master/LINKED%20LIST/Palindrome.cpp

I am getting a runtime error in 1 of the test cases. Please help me in removing that.

Hello @vidyajaykushwaha,

Runtime error can occur due to following reasons:

  1. Invalid memory access during run-time.
  2. Accessing linked list nodes that do not exist.
  3. Dividing by zero.
  4. Large allocation of memory together/Large Static Memory Allocation.
  5. Making a silly mistake.

In your code, you must be facing 2.
Your code would run perfectly, if it contains even number of elements.
But, for odd number of elements, it will give run-time array(if given list is palindrome).

Wondering Why?
Let’s understand with an example:
5
1 2 3 2 1
In the last iteration, both front and back of the linked list is the node with value 3.
Now, here comes the problem:
l.pop_back(); // This will delete the 3, and list is empty now.
l.pop_front(); // What would you pop now? RUNTIME ERROR

Hope, this would help.
Give a like, if you are satisfied.

As you asked me to give the code in codeblocks ide only. LInk: https://ide.codingblocks.com/s/109481

But you haven’t modified it for the mistakes.

Please, do the needful changes as specified in my previous reply.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.