C++ 数据结构 二叉树头文件

论坛 期权论坛 期权     
匿名   2018-4-29 11:24   4811   2
跪求::《数据结构与算法分析(C++版)(第二版)A.Shaffer著》里面的二叉树的头文件啊?最好是和书里面一模一样的,其他的也行,但要是对的,,,谢了谁能把里面的所有的头文件发上来也行。
分享到 :
0 人收藏

2 个回复

倒序浏览
2#
热心网友  15级至尊 | 2018-4-30 01:03:54
//   BinaryTreeNode.h:   interface   for   the   BinaryTreeNode   class.
//
//////////////////////////////////////////////////////////////////////

#if   !defined(AFX_BINARYTREENODE_H__65C73C3B_E763_40D9_8460_F5703119C756__INCLUDED_)
#define   AFX_BINARYTREENODE_H__65C73C3B_E763_40D9_8460_F5703119C756__INCLUDED_

#if   _MSC_VER   >   1000
#pragma   once
#endif   //   _MSC_VER   >   1000

template      class   BinaryTree;
template      class   BinarySearchTree;

template   
class   BinaryTreeNode
{
friend   class   BinaryTree  ;
friend   class   BinarySearchTree  ;
private:
T     element;                               //二叉树结点数据域
BinaryTreeNode  *     left;   //二叉树结点指向左子树的指针
BinaryTreeNode  *     right;   //二叉树结点指向左子树的指针

public:
BinaryTreeNode();
BinaryTreeNode(const   T&   ele); //给定数据的构造函数
BinaryTreeNode(const   T&   ele,BinaryTreeNode*   l,   BinaryTreeNode*   r);//给定数据的左右指针的构造函数
T     value()   const; //返回当前结点的数据
BinaryTreeNode  &   operator=   (const   BinaryTreeNode  &   Node)
{this=Node;}; //重载赋值操作符
BinaryTreeNode  *     leftchild()   const; //返回当前结点指向左子树的指针
BinaryTreeNode  *     rightchild()   const; //返回当前结点指向右子树的指针
        void     setLeftchild(BinaryTreeNode  *); //设置当前结点的左子树
        void     setRightchild(BinaryTreeNode  *); //设置当前结点的右子树

void     setValue(const   T&   val); //设置当前结点的数据域
bool     isLeaf()   const; //判定当前结点是否为叶结点,若是返回true
};

    //***************************************************************************//
  //**********************Class   BinaryTreeNode   Implementation******************//
//***************************************************************************//

template
BinaryTreeNode  ::BinaryTreeNode()
{
left=right=NULL;
}

template
BinaryTreeNode  ::BinaryTreeNode(const   T&   ele) //给定数据的构造函数
{
element=ele;
left=right=NULL;
}

template
BinaryTreeNode  ::BinaryTreeNode(const   T&   ele,BinaryTreeNode*   l,   BinaryTreeNode*   r)
//给定数据的左右指针的构造函数
{
element=ele;
left=l;
right=r;
}

template
T     BinaryTreeNode  ::value()   const
{
return   element;
}

template
BinaryTreeNode  *     BinaryTreeNode  ::leftchild()   const
{
return   left;
} //返回当前结点指向左子树的指针

template
BinaryTreeNode  *     BinaryTreeNode  ::rightchild()   const
{
return   right; //返回当前结点指向右子树的指针
}

template
void     BinaryTreeNode  ::setLeftchild(BinaryTreeNode  *   subroot)//设置当前结点的左子树
{
left=subroot;
}

template
void     BinaryTreeNode  ::setRightchild(BinaryTreeNode  *   subroot)//设置当前结点的右子树
{
right=subroot;
}

template
void     BinaryTreeNode  ::setValue(const   T&   val) //设置当前结点的数据域
{
element   =   val;
}

template
bool     BinaryTreeNode  ::isLeaf()   const //判定当前结点是否为叶结点,若是返回true
{
return   (left   ==   NULL)   &&   (right   ==   NULL);
}

#endif   //   !defined(AFX_BINARYTREENODE_H__65C73C3B_E763_40D9_8460_F5703119C756__INCLUDED_)
3#
热心网友  15级至尊 | 2018-4-30 01:03:55
你给个邮箱啊!我直接发给你吧!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:58388
帖子:6688
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP