1、先序遍历二叉树
void Preorder (BiTree T,void(*visit)(TElemType&e))
{
if(T){
visit(T->data);
Preorder(T->lchild,visit);
preorder(T->rchild,visit);
}
}
2、中序遍历二叉树
void Inorder (BiTree T,void(*visit)(TElemType&e))
{if(T){
Inreorder(T->lchild,visit);
visit(T->data);
Inreorder(T->rchild,visit);
}
}
3、后序遍历二叉树
void Post order(BiTree T,void(*visit)(TElemType&e))
{
if(T){
postreorder(T->lchild,visit);
Postreorder(T->rchild,visit);
visit(T->data);
}
}
3、线索二叉树
指向该线性序列中的前驱和后继的指针,称作线索,包含线索的存储结构
被称作线索链表,相对应的二叉树称作线索二叉树。
4、线索链表中结点的约定
Lchild域的指针指向其左子树,左标志域的值为0或Link,指向前驱为1或Thread。
rchild域中的指针指向右子树,值为Link或0;否则指向后继,为线索Thread或1。
5、线索链表的描述
typedef enum{LTag,RTag} PointerThr;
typedef struct BiThrNode{
TElemType data;
struct BiThrNode *lchild,*rchild;
PointerThr LTag,RTag;
}BiThrNode,*BiThrTree;
6、树的三种存储结构
双亲表示法:
#define MAX_TREE_SIZE 100
typedef struct PTNode{
Elem data;
int parent;
}PTNode;
typedef struct{
PTNode nodes[MAX_TREE_SIZE];
int r,n;
}PTree;
孩子表示法:
typedef struct CTNode{
int child;
struct CTNode *next;
}*ChildPtr;
typedef struct{
Elem data;
ChildPtr firstchild;
}CTBox;
孩子兄弟表示法:
typedef struct CSNode{
Elem data;
struct CSNode *firstchild,*nextsibling;
}CSNode,*CSTree;
七、森林转换为二叉树
左是孩子,右是兄弟。
八、树的遍历
先序遍历:根,左,右。
后序遍历:左,右,根。