You are given a doubly linked list with a head and tail poin…
You are given a doubly linked list with a head and tail pointer and this list represents a number. Each node of the linked list stores a single digit of the number and the head points to the most significant digit. Example a number “3530” is represented as: head ↔ 3 ↔ 5 ↔ 3 ↔ 0 ↔ tail Write a function in C++ or using pseudocode that takes as input the head of the list and checks if the number is palindrome or not without using any other data structure. The function must return a boolean indicating if the number is a palindrome or not. The head of the list is a pointer which points to the first Node and the tail of the list points to the last node. It is possible to have an empty list, in which case it is considered a palindrome. * Definition for doubly-linked list. struct ListNode { int digit; ListNode *next, *prev; ListNode(int x, ListNode *nex, ListNode *pre) : digit(x), next(nex), prev(pre) {}}; Example 1:Input: head ↔ 3 ↔ 5 ↔ 3 ↔ 0 ↔ tailOutput: false Example 2:Input: head ↔ 3 ↔ 5 ↔ 5 ↔ 3 ↔ tailOutput: true
Read Details