代码的注释已经很清楚了,就不多做解释了。
#include <stdio.h>
#include <iostream>
using namespace std;
typedef struct STreeNode* pSTreeNode;
typedef int TreeDataType;
struct STreeNode {
TreeDataType data;
pSTreeNode pFirstChild; // 左孩子节点,表示第一个儿子节点
pSTreeNode pNextBrother; // 右兄弟节点,下一个兄弟节点
STreeNode(TreeDataType val) {
data = val;
pFirstChild = NULL;
pNextBrother = NULL;
}
};
class CTree {
public:
CTree();
CTree(TreeDataType val);
~CTree();
public:
void insertByData(TreeDataType parentValue, TreeDataType Value);
void insertBrother(pSTreeNode pBrotherNode, TreeDataType Value);
pSTreeNode search(pSTreeNode pNode, TreeDataType Value);
void preOrder(pSTreeNode pNode);
void inOrder(pSTreeNode pNode);
void postOrder(pSTreeNode pNode);
void printNode(pSTreeNode pNode);
void FreeMemory(pSTreeNode pNode);
public:
pSTreeNode pRoot;
};
void CTre