2

我正在尝试复制给定的 BST

假设我得到了这个:

   2
  / \
 1   3

我想做的是:

      2
     / \
    2   3
   /   /
  1   3
 /
1
void bTree::mulTree(tNode *tree)
{
    if (!tree)
        return;
    if (tree->left)
        tree->left->left = insert(tree->left->value);
    else
        tree->left = insert(tree->value);

    mulTree(tree->left->left);

    if (tree->value != tree->left->value)
    {
        tree->left->value = tree->value;
        mulTree(tree->right);
    }
}

使用此代码,我得到了应有的左侧,
但是如果我尝试在右侧进行更改,则会出现堆错误

"//mulTree(tree->right);"  

如果我运行它,我会得到:
"HEAP: Free Heap block ... after it was freed"
但我不明白它已经在哪里被释放了...... =\

我在此期间收到错误:

tree->left = insert(tree->value);

插入代码:

tNode* bTree::insert(int value)
{
    tNode *temp = new tNode();
    temp->value = value;
    return temp;
}
4

0 回答 0