Bir BST için bazı yöntemler kodlamak var ve bazı sorunlar var, açıklamama izin ver.
Aşağıdaki yapılara sahip:
struct node {
struct node *lChild;
struct node *rChild;
int value;
};
ve
struct tree {
struct node *root;
};
Aşağıdaki fonksiyonları ile birlikte:
struct tree* constructNewTree()
{
struct tree *T=malloc(sizeof(struct tree));
T->root=NULL;
return T;
}
ve
struct node* constructNewNode(int i)
{
struct node *N=malloc(sizeof(struct node));
N->value=i;
N->lChild=NULL;
N->rChild=NULL;
return N;
}
Ve benim main ben (örneğin) bu aramalıdır:
int main()
{
struct tree *T;
T=constructNewTree();
insertKey(5,T);
insertKey(2,T);
insertKey(9,T);
return 0;
}
Ne yapmak zorunda fonksiyon insertKey oluşturmaktır (i, yapı ağacı * T int) özyineleme kullanarak.
Ben böyle bir şey yapmak istedim
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);
}
}
}
Ama bana yine insertKey çağırmak ama bir düğüm ve bir ağaç aynı şekilde kullanmak gibi olamaz sağlayacak özyineleme kullanılarak çok uzak almaz.
Herkes bana verilen yapıların değiştirmeden bunu yapabilir biliyor mu?
Çok teşekkür ederim.













