diff --git a/_04.树/03线索二叉树_ThreadBinaryTree - 副本.c b/_04.树/03线索二叉树_ThreadBinaryTree - 副本.c deleted file mode 100644 index a17ac2f..0000000 --- a/_04.树/03线索二叉树_ThreadBinaryTree - 副本.c +++ /dev/null @@ -1,139 +0,0 @@ -#include "string.h" -#include "stdio.h" -#include "stdlib.h" -#include "io.h" -#include "math.h" -#include "time.h" - -#define OK 1 -#define ERROR 0 -#define TRUE 1 -#define FALSE 0 - -#define MAXSIZE 100 /* 洢ռʼ */ - -typedef int Status; /* StatusǺ,ֵǺ״̬,OK */ -typedef char TElemType; -typedef enum {Link,Thread} PointerTag; /* Link==0ʾָҺָ, */ - /* Thread==1ʾָǰ̵ */ -typedef struct BiThrNode /* 洢ṹ */ -{ - TElemType data; /* */ - struct BiThrNode *lchild, *rchild; /* Һָ */ - PointerTag LTag; - PointerTag RTag; /* ұ־ */ -} BiThrNode, *BiThrTree; - -TElemType Nil='#'; /* ַԿոΪ */ - -Status visit(TElemType e) -{ - printf("%c ",e); - return OK; -} - -/* ǰнֵ,T */ -/* 0()/ո(ַ)ʾս */ -Status CreateBiThrTree(BiThrTree *T) -{ - TElemType h; - scanf("%c",&h); - - if(h==Nil) - *T=NULL; - else - { - *T=(BiThrTree)malloc(sizeof(BiThrNode)); - if(!*T) - exit(OVERFLOW); - (*T)->data=h; /* ɸ(ǰ) */ - CreateBiThrTree(&(*T)->lchild); /* ݹ鹹 */ - if((*T)->lchild) /* */ - (*T)->LTag=Link; - CreateBiThrTree(&(*T)->rchild); /* ݹ鹹 */ - if((*T)->rchild) /* Һ */ - (*T)->RTag=Link; - } - return OK; -} - -BiThrTree pre; /* ȫֱ,ʼָոշʹĽ */ -/* */ -void InThreading(BiThrTree p) -{ - if(p) - { - InThreading(p->lchild); /* ݹ */ - if(!p->lchild) /* û */ - { - p->LTag=Thread; /* ǰ */ - p->lchild=pre; /* ָָǰ */ - } - if(!pre->rchild) /* ǰûҺ */ - { - pre->RTag=Thread; /* */ - pre->rchild=p; /* ǰҺָָ(ǰp) */ - } - pre=p; /* preָpǰ */ - InThreading(p->rchild); /* ݹ */ - } -} - -/* T,,Thrtָͷ */ -Status InOrderThreading(BiThrTree *Thrt,BiThrTree T) -{ - *Thrt=(BiThrTree)malloc(sizeof(BiThrNode)); - if(!*Thrt) - exit(OVERFLOW); - (*Thrt)->LTag=Link; /* ͷ */ - (*Thrt)->RTag=Thread; - (*Thrt)->rchild=(*Thrt); /* ָָ */ - if(!T) /* ,ָָ */ - (*Thrt)->lchild=*Thrt; - else - { - (*Thrt)->lchild=T; - pre=(*Thrt); - InThreading(T); /* */ - pre->rchild=*Thrt; - pre->RTag=Thread; /* һ */ - (*Thrt)->rchild=pre; - } - return OK; -} - -/* T(ͷ)ķǵݹ㷨 */ -Status InOrderTraverse_Thr(BiThrTree T) -{ - BiThrTree p; - p=T->lchild; /* pָ */ - while(p!=T) - { /* ʱ,p==T */ - while(p->LTag==Link) - p=p->lchild; - if(!visit(p->data)) /* ΪյĽ */ - return ERROR; - while(p->RTag==Thread&&p->rchild!=T) - { - p=p->rchild; - visit(p->data); /* ʺ̽ */ - } - p=p->rchild; - } - return OK; -} - -int main() -{ - BiThrTree H,T; - printf("밴ǰ(:'ABDH##I##EJ###CF##G##')\n"); - CreateBiThrTree(&T); /* ǰ */ - InOrderThreading(&H,T); /* , */ - printf("():\n"); - InOrderTraverse_Thr(H); /* () */ - printf("\n"); - - return 0; -} - - diff --git a/_04.树/_c.线索二叉树.c b/_04.树/_c.线索二叉树.c index 69adf8c..5586135 100644 --- a/_04.树/_c.线索二叉树.c +++ b/_04.树/_c.线索二叉树.c @@ -2,7 +2,7 @@ * @Author: Xu Bai * @Date: 2019-07-23 22:43:14 * @LastEditors: Xu Bai - * @LastEditTime: 2019-07-27 23:26:33 + * @LastEditTime: 2019-07-27 23:35:31 */ #include "string.h" #include "stdio.h" @@ -40,7 +40,7 @@ Status visit(ElemType e) return OK; } -Status CreateBiThrTree(BiThrNode *T) +Status CreateBiThrTree(BiThrTree *T) { ElemType h; scanf("%c", &h); @@ -148,7 +148,7 @@ Status InOrderTraverse_Thr(BiThrTree T) /*ΪյĽ */ return ERROR; } - while (p->RTag == Thread && p->rchid != T) + while (p->RTag == Thread && p->rchild != T) { p = p->rchild; visit(p->data); @@ -162,7 +162,7 @@ int main() { BiThrTree H, T; - printf("밴ǰ(:'ABDH##I##EJ###CF##G##')\n"); + printf(":'ABDH##I##EJ###CF##G##')\n"); CreateBiThrTree(&T); /* ǰ */ InOrderThreading(&H, T); /* , */ printf("():\n"); diff --git a/a.out b/a.out new file mode 100644 index 0000000..3175edd Binary files /dev/null and b/a.out differ