감사합니다. 지금은 의도 한대로 작동하지 않습니다. 프로그램을 실행하면 "bst.exe가 작동을 멈췄습니다"라는 오류가 발생하고이 기능에서 오류가 발생합니다.바이너리 검색 트리 삽입 (C)
static NODE *insert_i(NODE *r, int x)
{
NODE *leaf;
while(r)
{
if(r->val == x)
return r;
if(x < r->val && r->left != NULL)
r = r->left;
else if(x > r->val && r->right != NULL)
r = r->right;
}
leaf = malloc(sizeof(NODE));
leaf->left = NULL;
leaf->right = NULL;
leaf->val = x;
count++;
if(x < r->val)
r->left = leaf;
else
r->right = leaf;
return r;
}
void bst_insert(BST_PTR t, int x)
{
t->root = insert_i(t->root, x);
}
if (r == NULL) // 새 트리 ... 이것은 while 루프 앞에 있어야합니다 – Deepthought