0

Doing a problem on how to convert a binary tree to a doubly linked list tree in the void po() function we are passing root node and 2 nodes as their address and now i want to set the right of one of the reference node i am doing the below way and getting error anyone know how to solve this ???

void po(Node* root,Node **p,Node**q){
        if(p==NULL)
            return;
        po(root->left,p,q);
        if(*p==NULL){
            *p=root;
            *q=root;
        }
        else{
            *(q)->right=root; // This line contain error !!!
            root->left=*q;
            *q=root;
        }
        po(root->right,p,q);
    }
    Node * bToDLL(Node *root)
    {
        if(root==NULL )
            return root;
        Node* a=NULL;
        Node* b=NULL;
        po(root,&a,&b);
        return a;
    }

Error :- error: request for member right in * q, which is of pointer type Node* (maybe you meant to use -> ?) *(q)->right=root; ^

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
Aditya Aggarwal
  • 159
  • 1
  • 9

1 Answers1

2

This statement

*(q)->right=root;

actually looks like

*(q->right) = root;

because the postfix operator -> has a higher precedence relative to the unary operator *.

But q is a pointer to pointer. So the pointed pointer does not have a data member right.

It seems you mean

( *q )->right = root;

In this case the expression *q points to an object of a structure type.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335