我做了一个二叉树类,它保存: int
值,BinaryTree* left
,BinaryTree* right
。C++二叉树递归析构问题
class BinaryTree {
private:
int value;
BinaryTree* left;
BinaryTree* right;
bool isVisited;
public:
BinaryTree();
BinaryTree createComplete(int n);
~BinaryTree();
}
我的析构函数是:
BinaryTree::~BinaryTree() {
delete left;
delete right;
}
在克利翁它完美运行时,但在我的终端,我得到一个 段错误(核心转储)。我看到的每个地方都声称这应该是破坏者。任何阐述都会有所帮助!
我不是一个计算器专家,我更新了我的〜二叉树功能仍然得到段错误:
BinaryTree::~BinaryTree() {
if (right != NULL) {
delete right;
}
if (left != NULL) {
delete left;
}
}
你也可以显示构造函数的定义吗? –
你如何建立你的BST?你能发布足够的代码,我们可以在我们的结尾重现这个问题吗? – templatetypedef