本人刚学数据结构,对树的基本功能网上找不到C++代码

便自己写了一份,贴出方便大家进行测试和学习。

大部分功能未测试,如有错误或者BUG,请高手们指教一下,谢谢。

 

结点声明:

BinTreeNode.h

 1 template<typename ElemType>
 2 struct BinTreeNode
 3 {
 4     ElemType data;                     //数据元素
 5     BinTreeNode<ElemType> *leftChild;  //指向左孩子的指针
 6     BinTreeNode<ElemType> *rightChild; //指向右孩子的指针
 7     BinTreeNode<ElemType> *pre;        //指向双亲的指针
 8 
 9     //函数构造
10     BinTreeNode();
11     BinTreeNode(const ElemType &val,
12         BinTreeNode<ElemType> *lChild=NULL,
13         BinTreeNode<ElemType> *rChild=NULL);
14     BinTreeNode<ElemType> &operator =(const BinTreeNode<ElemType> &copy);
15 };
16 
17 template<typename ElemType>
18 BinTreeNode<ElemType>::BinTreeNode()
19 {
20     leftChild=rightChild=pre=NULL;
21 }
22 
23 template<typename ElemType>
24 BinTreeNode<ElemType>::BinTreeNode(const ElemType &val,
25                         BinTreeNode<ElemType> *lChild,
26                         BinTreeNode<ElemType> *rChild)
27 {
28     data=val;
29     leftChild=lChild;
30     rightChild=rChild;
31     pre=NULL;
32 }
33 
34 template<typename ElemType>
35 BinTreeNode<ElemType> &BinTreeNode<ElemType>::operator =(const BinTreeNode<ElemType> &copy)
36 {
37     data=copy.data;
38     leftChild=copy.leftChild;
39     rightChild=copy.leftChild;
40     pre=copy.pre;
41 }
BinTreeNode.h

相关文章:

  • 2022-12-23
  • 2022-01-13
  • 2021-12-11
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-19
猜你喜欢
  • 2021-04-26
  • 2021-12-02
  • 2021-06-26
  • 2022-01-29
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
相关资源
相似解决方案