正在学二叉树 请教几个问题
这是教材上给的声明:
template <class Type> class BinaryTree;
template <class Type> class BinTreeNode
{
friend class BinaryTree <Type>;
public:
BinTreeNode() {leftChild=0;rightChild=0;}
BinTreeNode(Type item,BinTreeNode <Type> *left=0,BinTreeNode <Type> *right=0) {data=item;leftChild=left;rightChild=right;}
Type &GetData() const {return data;}
BinTreeNode *GetLeft() const {return leftChild;}
BinTreeNode *GetRight() const {return rightChild;}
void SetData(const Type &item) {data=item;}
void SetLeft(BinTreeNode <Type> *L) {leftChild=L;}
void SetRight(BinTreeNode <Type> *R) {rightChild=R;}
private:
BinTreeNode <Type> *leftChild,*rightChild;
Type data;
};
template <class Type> class BinaryTree
{
public:
BinaryTree() {root=0;}
BinaryTree(Type value) {RefValue=value;root=0;}
virtual ~Binary() {destroy(root);}
virtual int IsEmpty() {return root==0?1:0;}
virtual BinTreeNode <Type> *Parent(BinTreeNode <Type> *current) {return root==0 || root==current?0:Parent(root,current);}
virtual BinTreeNode <Type> *LeftChild(BinTreeNode <Type> *current) {return root!=0?current->leftChild:0;}
virtual BinTreeNode <Type> *RightChild(BinTreeNode <Type> *current) {return root!=0?current->rightChild:0;}
virtual int Insert(const Type &item);
virtual int Find(const Type &item) const;
const BinTreeNode <Type> *GetRoot() const {return root;}
friend istream &operator>>(istream &,BinTree <Type> &Tree);
friend ostream &operator < <(ostream &,BinTree <Type> &Tree);
private:
BinTreeNode <Type> *root;
Type RefValue;
BinTreeNode <Type> *Parent(BinTreeNode <Type> *start,BinTreeNode <Type> *current);
int Insert(BinTreeNode <Type> * ¤t,const Type &item);
void Traverse(BinTreeNode <Type> *current,ostream &out) const;
int Find(BinTreeNode <Type> *current,const Type &item) const;
void destroy(BinTreeNode <Type> *current);
};