AVL树分割函数

问题描述 投票:0回答:0

假设所有辅助函数都正常工作,为什么我的拆分 avl 树函数不起作用? 请注意 struct def 有一个父字段,该函数旨在根据需要更新父指针。运行程序时,函数不会终止。它成功地在非常具体的例子上有所分裂。我一直在努力弄清楚我的功能有什么问题。我真的很想了解它有什么问题,因为在我看来它应该按预期工作。

void splitAVL(AVLNodePtr root, int k, AVLNodePtr* T1, AVLNodePtr* T2)
 {
    if (root == NULL) {
        *(T1) = *(T2) = NULL;
        return;
    }

    if(k == root->key)
    {
        root->child[LEFT]->parent = NULL;
        root->child[RIGHT]->parent = NULL;
        *(T1) = root->child[LEFT];
        *(T2) = root->child[RIGHT];
        *(T2) = avl_insert(T2,root->key,root->y);
        free(root);
        return;
    }

    else if (k < root->key)
    {
        splitAVL(root->child[LEFT], k, T1,T2);
        root->parent = NULL;
       *(T1) = concAVL(root->child[LEFT],new_avl_node(root->key,root->y),*(T1));
       free(root);
       return;
    }


    else
    {
        splitAVL(root->child[RIGHT], k, T1,T2);
        root->parent = NULL;
        *(T2) = concAVL(*(T2),new_avl_node(root->key,root->y),root->child[RIGHT]);
        free(root);
        return;
    }

}
c debugging split binary-search-tree avl-tree
© www.soinside.com 2019 - 2024. All rights reserved.