急!急!求二叉排序树程序

来源:百度知道 编辑:UC知道 时间:2024/06/01 09:03:18
设计一个读入一串整数构成一棵二叉排序树完整程序
要C++的,我是初学者最好注释详细一点,谢谢啦!

#include <iostream.h>
//二叉排序树类的前视定义
template<class Type> class BSTree;
//二叉排序树结点类的定义
template<class Type>
class BSTreeNode
{friend class BSTree <Type>;
private:
Type data; //数据域(在此为关键字)
BSTreeNode <Type> *leftChild, *rightChild;
public:
BSTreeNode():leftChild(NULL),rightChild (NULL){};//构造函数
BSTreeNode(const Type &d) : data (d), leftChild (NULL),rightChild (NULL) {} ; //构造函数
~BSTreeNode(){}; //析构函数
};

//二叉排序树的类定义
template <class Type>
class BSTree
{
private:
BSTreeNode<Type> * root; //二叉排序树的根指针

void Insert ( const Type & x, BSTreeNode<Type> *&p );
//在p为根的二叉排序树上插入数据元素x
void Delete ( const Type & k, BSTreeNode<Type> *&p );

//在p为根的二叉排序树上删除关键字为k的结点
BSTreeNode<Type> * Min(BSTreeNode<Type> *p);
BSTreeNode<Type> * Find(const Type &k, BSTreeNode<Type> *p );
//在