Tengo que codificar algunos métodos para la BST y tengo algunos problemas, me explico.
Tengo las siguientes estructuras:
struct node {
struct node *lChild;
struct node *rChild;
int value;
};
y
struct tree {
struct node *root;
};
junto con las siguientes funciones:
struct tree* constructNewTree()
{
struct tree *T=malloc(sizeof(struct tree));
T->root=NULL;
return T;
}
y
struct node* constructNewNode(int i)
{
struct node *N=malloc(sizeof(struct node));
N->value=i;
N->lChild=NULL;
N->rChild=NULL;
return N;
}
Y en mi principal Debo llamar a este (por ejemplo):
int main()
{
struct tree *T;
T=constructNewTree();
insertKey(5,T);
insertKey(2,T);
insertKey(9,T);
return 0;
}
Lo que tengo que hacer es crear el insertKey función (int i, estructura de árbol * T) usando la recursión.
Yo quería hacer algo como
void insertKey(int i, struct tree *T)
{
if (T->root==NULL) {
T->root=constructNewNode(i);
return;
}
else {
if (i<=T->root->value) {
T->root->lChild=constructNewNode(i);
else if (i>T->root->value) {
T->root->rChild=constructNewNode(i);
}
}
}
Pero no llegó muy lejos, utilizando la recursividad permitiría que llame a insertKey nuevo, pero me parece que no puede utilizar un nodo y un árbol de la misma manera.
¿Alguien sabe cómo podría hacerlo sin alterar las estructuras dadas?
Muchas gracias.













