0

私は私の AVL ツリーで少し助けを求めています。これは私が学校関連のプロジェクトとして取り組んでいるものです。私は自分が間違っていることにかなり迷っています。

再帰的に挿入する挿入関数があり、ノードがリンクしていません。私はそれがマイナーであることを知っていますが、ほとんどの道をテストしたように感じます

私の挿入機能は次のとおりです

 void Tree::Insert(int & entry, Node * nextEntry)
{
//Temp node declared for use in the function
    Node * temp = nullptr;
    //Check if the value is equal
    if (nextEntry != nullptr && nextEntry->value == entry)
    {
        if (entry == nextEntry->value)
        {
            cout << "\n\t DUPLICATE DATA FOUND\n";

        }
    }


    //Going to the left side
    if (nextEntry != nullptr && entry < nextEntry->value )
    {
        temp = nextEntry->leftChild;
        nextEntry->balanceFactor++;
        Insert(entry, temp);

    }
    //Check to make sure that the root isnt empty


    //Going to the right side 
    if (nextEntry != nullptr && entry > nextEntry->value )
    {
        temp = nextEntry->rightChild;
        nextEntry->balanceFactor--;

      Insert(entry, temp);
    }
        if (nextEntry == nullptr)
    {
            nextEntry = new Node(entry);

    }
    if (nextEntry->balanceFactor >= balanceExceededLeft || nextEntry->balanceFactor <= balanceExceededRight)
    {
BalanceTree(nextEntry);
    }

}

お時間をいただきありがとうございます。

4

0 に答える 0