struct node* newnode(int data) /*this is a function declaration of type pointer to node */
{
struct node* node=(struct node*)malloc(sizeof(struct node));
node->data=data;
node->left=NULL;
node->right=NULL;
return (node);
}
struct node* insert(node* tree,int data)
{
if(tree==NULL)
{
return newnode(data);
}
else if(tree->data>data)
{
tree->left=insert(tree->left,data);
}
else
{
tree->right=insert(tree->right,data);
}
return (tree);
}
main()
{
struct node* root=NULL;
root=insert(root,3);
}
почему нам нужно возвращать адрес (дерева) в функции вставки (узел * дерево, целые данные), поскольку мы отправляем адрес root во вставке (узел * дерево, целые данные)