0

私は二分探索木を扱っています。ここでは、ツリーからアイテムを削除する関数を書いています。次のコードでは:

if(root = NULL)//if there is nothing in the tree
{
    cout<<"the Tree is empty"<<endl;//ouput to the screen
    return;//exit the function
}

bool isFound = false;//tells us if the item is found
Node* tmp = new Node();//declare a temp pointer
Node* tmp2 = new Node();;//declare a temp pointer
tmp* = *root;//assign the pointer to something

コピー コンストラクターを呼び出していますが、現在は次のように値をコピーしているだけです。

Node& Node::operator= (const Node& node)
{
    data = node.data;
    left = node.left;
    right = node.right;
    return *this;
}
4

2 に答える 2

1

必要なオブジェクトを割り当てるために、ポインタを割り当てています

*tmp = *root;

tmpおよびrootタイプNode*です。*tmpおよび*rootタイプはNodeです。

于 2013-03-13T11:38:34.330 に答える
0
if(root = NULL)

に変更します

if(root == NULL)

それも間違っています:

tmp* = *root;//assign the pointer to something
于 2013-03-13T11:43:18.080 に答える