9-12.h

来自「清华大学出版社出版的c++程序设计课本」· C头文件 代码 · 共 58 行

H
58
字号
//9-12.h
#ifndef BINARYTREE_CLASS
#define BINARYTREE_CLASS

#include <iostream.h>
#include <stdlib.h>

#ifndef NULL
const int NULL = 0;
#endif  // NULL
#include "9-11.h"

template <class T>
class binaryTree
{
   public:
       binaryTree();    //构造函数
       ~binaryTree();   //析构函数
       bool isEmpty();   //判断树空否
       TreeNode<T>* getroot() const;   //取得根结点
   protected:
       TreeNode<T>* root;
};
    
    //构造函数
template <class T>
binaryTree<T>::binaryTree()
{
    root=NULL;
}

//析构函数
template <class T>
binaryTree<T>::~binaryTree()
{
    if(root)
    {
       root->release();   //删除根结点的左右子树
       delete root;       //释放根结点
       root=NULL;
    }
}

//判断树空否
template <class T>
bool binaryTree<T>:: isEmpty()
{
    return root==NULL;
}

//取得根结点
template <class T>
TreeNode<T>* binaryTree<T>::getroot() const
{
    return root;
}
#endif  // BINARYTREE_CLASS

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?