error: void value not ignored as it ought to be , how can I solve this issue?

25 views Asked by At
void preorderTraversal(struct node*tree)
{

    if (tree != NULL)
    {
        printf("%d", tree->data);
        tree->left=preorderTraversal(tree->left);
        tree->right = preorderTraversal(tree->right);
    }
}
1

There are 1 answers

0
abelenky On

Function preorderTraversal is declared void.

That is, it does not return any value.

But on these lines:

tree->left = preorderTraversal(tree->left);
tree->right = preorderTraversal(tree->right);

You are treating it as if it returns a value that can be assigned to ->left and ->right