小编Mat*_* S.的帖子

二进制搜索树的析构函数

我正在尝试为我的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)

c++ destructor

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

destructor ×1