I've got some problem here with struct. I have create a struct and a function to try to understand how the tree data structure works.Now the problem is that when I try to compile the following code with the command gcc test.c -o test, the compiler always return the error message error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token, please give me some help.
#include <stdio.h>
#include <stdlib.h>
typedef struct BiTNode
{
int data;
struct BiTNode *lchild, *rchild;
}BiTNode, *BiTree;
void createTree(BiTree &T)
{
int i;
scanf("%d", &i);
if(i == -1)
{
T = NULL;
}
else
{
T = (BiTNode *)malloc(sizeof(BiTNode));
T->data = i;
createTree(T->lchild);
createTree(T->rchild);
}
}
int main(void)
{
BiTNode* root = NULL;
createTree(root);
return 0;
}
BiTNodeintypedef struct BiTNodeis redundant.rootto be bon NULL after thecreateTree(root);statement ?BiTNodein thetypedef struct BiTNodeprevents the following compiler warning on the two lines:createTree(T->lchild); createTree(T->rchild);:warning: incompatible pointer types passing 'struct BiTNode *' to parameter of type 'BiTree'. At least that's what my compiler tells me. Give it a try.