我正在尝试为我的Binary Search Tree编写析构函数,并且我知道如何递归遍历该树,但是我不知道如何在析构函数中执行此操作,以便删除每个节点。
我的标题是:
struct Node;
typedef string TreeType;
typedef Node * TreePtr;
//Defines a Node
struct Node
{
TreeType Info;
int countDuplicates = 1;
TreePtr Left, Right;
};
class Tree
{
public:
//Constructor
Tree();
//Destructor
~Tree();
//Retruns true if the tree is Empty
bool Empty();
//Inserts a Node into the tree
bool Insert(TreeType);
//Delete decides what type of delection needs to occur, then calls the correct Delete function
bool Delete(Node * , Node * );
//Deletes a leaf node …Run Code Online (Sandbox Code Playgroud)