我尝试创建 detor 并得到一个“堆栈溢出”我知道为什么但我希望它的工作......
#include <iostream>
#include "printTreeToFile.h"
#include "BSNode.h"
#define _BS BSNode::
#define _BSNode _BS BSNode
_BS ~BSNode()
{
Del(this);
}
void _BS Del(BSNode *x,int y)
{
if (x->isLeaf())
{
delete x;
return;
}
if (x->_Right != NULL)
Del(x->_Right,y += 1);
if (x->_Left != NULL)
Del(x->_Left,y += 1);
if (y != 1)
{
delete x;
}
return;
}
Run Code Online (Sandbox Code Playgroud)
我尝试以递归方式执行此操作,但是对 Del 的删除调用因此我们获得了无限循环