C++ 二叉搜索树赋值运算符(递归)

C++ 二叉搜索树赋值运算符(递归),c++,recursion,binary-search-tree,assignment-operator,C++,Recursion,Binary Search Tree,Assignment Operator,我在理解如何实现这一点上遇到了巨大的困难 这是我到目前为止尝试过的原型和实现(请注意,其中两次尝试被注释掉了-标记为(1)和(2) 下面是赋值运算符的实现: //--- Definition of operator= template <typename DataType> BST<DataType>& BST<DataType>::operator=(const BST& origList) { if (this != &origL

我在理解如何实现这一点上遇到了巨大的困难

这是我到目前为止尝试过的原型和实现(请注意,其中两次尝试被注释掉了-标记为(1)和(2)

下面是赋值运算符的实现:

//--- Definition of operator=
template <typename DataType>
BST<DataType>& BST<DataType>::operator=(const BST& origList)
{
 if (this != &origList)
 {
    copyTree(origList.myRoot, myRoot);
    destroy(myRoot);
 }
 return *this;
}
/---运算符的定义=
模板
BST&BST::operator=(常量BST&origList)
{
如果(此!=&origList)
{
copyTree(origList.myRoot,myRoot);
破坏(myRoot);
}
归还*这个;
}
以下是copyTree递归函数:

/---复制构造函数()的定义
模板
英国夏令时:英国夏令时(英国夏令时和英国夏令时)
{
copyTree(origList.myRoot,myRoot);
}
//---copyTree()的定义
模板
void BST::copyTree(binnodepener origRoot、binnodepener和subtreeRoot)
{
if(origRoot==0)
subtreeRoot=NULL;
其他的
{
subtreeRoot=新的BinNode(origRoot->data);
复制树(原根->左,次根->左);
复制树(原树->右,次树->右);
//origRoot=新的BinNode(subtreeRoot->data);
//复制树(subtreeRoot->left,origRoot->left);
//复制树(子树根->右侧,原始树->右侧);
}
}
复制构造函数工作得很好,但是赋值操作符我没有掌握这里需要什么。非常感谢任何帮助

另外,您可能已经注意到我有“origList”,它应该被命名为“origTree”,但是我从以前为LinkedList创建的构造函数中借用了它。

BST<DataType>& BST<DataType>::operator=(const BST& origList)
BST&BST::operator=(常量BST&origList)
应该是

BST<DataType>& BST<DataType>::operator=(const BST<DataType>& origList)
BST&BST::operator=(常量BST&origList)
在类中使用以下声明

BST<DataType>& operator=(const BST<DataType>& origList)
BST&operator=(常量BST&origList)

Ravi,谢谢你,代码可以编译!但是,当程序试图运行赋值运算符时出现以下消息:binaryst_10.1.exe中0x77c815de处未处理的异常:0xC0000005:访问冲突读取位置0xfeeefef6,我的逻辑一定有问题。
BST<DataType>& BST<DataType>::operator=(const BST& origList)
BST<DataType>& BST<DataType>::operator=(const BST<DataType>& origList)
BST<DataType>& operator=(const BST<DataType>& origList)