I'm trying to find palindromes in a given linked list by recursively going down to the last node in the list and comparing the first node with the last node in the list.
My LinkedList has standard Nodes with an int value member and a pointer to the next node.
I'm passing a pointer to the head node pointer as the first parameter and changing it to the next with each successful match, but I'm getting an error in the syntax. Can someone explain why I'm getting this error?
Code snippet:
bool isPalindromeRecur(Node** left, Node* right){
if(right == nullptr) return true;
bool isP = isPalindromeRecur(left,right->next);
if(!isP) return false;
bool isP1 = (*(left)->val == right->val);
*left = *(left)->next;
return isP1;
}
I am getting errors at lines 5 and 6.
error: request for member 'val' in '* left', which is of pointer type 'Node*' (maybe you meant to use '->' ?)
bool isP1 = (*(left)->val == right->val);
^~~
error: request for member 'next' in '* left', which is of pointer type 'Node*' (maybe you meant to use '->' ?)
*left = *(left)->next;
^~~~
Aucun commentaire:
Enregistrer un commentaire