为什么只插入根? (AVL树)[C]

时间:2017-02-12 20:56:47

标签: c malloc avl-tree

编辑:以前的问题已经解决了。我的AVL树的插入功能有问题。我现在坐在这已经很久了..我真的希望有人会读到这个,我不想创建一个新的线程

功能:

void AVL_insert_value(AVLTree* avlt, int value)
{

AVLNode* next=avlt->root;
AVLNode* current;

if (avlt->root==NULL){
        avlt->root=CreateNode(value);
        }
else {

        while(next!=NULL)
                {
                current=next;
                if(value < next->value) {
                        next=current->left;
                        }

                else if (value > next->value) {
                     next=current->right;
                        }
                else{
                        return;
                }

            if((value > current->value) && current->right==NULL) { current->right=CreateNode(value); }
            if((value < current->value) && current->left==NULL)  { current->left=CreateNode(value); }
        }
    }
}

所有结构都是typdef'd,CreateNode:

AVLNode* CreateNode(int value) {

AVLNode* newNode=malloc(sizeof(AVLNode));
newNode->left=newNode->right=NULL;
newNode->value=value;
newNode->height=1;
return newNode;
}

没有错误,没有警告,valgrind不会抱怨(即使是--leak-check = full),无论我做什么,只插入根...我在哪里丢失其他的?我究竟做错了什么?我会很感激任何帮助......

0 个答案:

没有答案