首页 二叉树的先序递归建立,中序线索化,中序遍历

二叉树的先序递归建立,中序线索化,中序遍历

举报
开通vip

二叉树的先序递归建立,中序线索化,中序遍历二叉树的先序递归建立,中序线索化,中序遍历 #include #include #define OK 1 #define ERROR 0 #define TRUE 1 #define FALSE 0 #define NULL 0 #define OVERFLOW -1typedef char TElemType;typedef int Status;typedef enum PointerTag{Link,Thread}; typedef struct BiThrNode { TElemType data; st...

二叉树的先序递归建立,中序线索化,中序遍历
二叉树的先序递归建立,中序线索化,中序遍历 #include #include #define OK 1 #define ERROR 0 #define TRUE 1 #define FALSE 0 #define NULL 0 #define OVERFLOW -1typedef char TElemType;typedef int Status;typedef enum PointerTag{Link,Thread}; typedef struct BiThrNode { TElemType data; struct BiThrNode *lchild, * rchild; PointerTag LTag,RTag; }BiThrNode, * BiThrTree;BiThrTree pre; Status CreatBiThrTree(BiThrTree &T)//递递递的方法先序构造二叉//{ char ch; scanf("%c",&ch); if (ch==' ') T=NULL; else { if (!(T=(BiThrNode *)malloc(sizeof(BiThrNode)))) return ERROR; T->data=ch; // 生成根点递递 CreatBiThrTree(T->lchild); // 构造左子递 CreatBiThrTree(T->rchild); // 构造右子递 } return OK; } // CreateBiThrTreevoid InThreading(BiThrTree p)//将点中序索化递递递递递递递//{ if(p) { InThreading(p->lchild); if(!p->lchild) { p->LTag=Thread; p->lchild=pre; } else { p->LTag=Link; } if(!pre->rchild) { pre->RTag=Thread; pre->rchild=p; } else { pre->RTag=Link; } pre=p; InThreading(p->rchild); } } Status InOrderThreading(BiThrTree &Thrt,BiThrTree T)//中序遍二叉,并将其中序索化递递递递递递递递递递递递递 // { if(!(Thrt=(BiThrTree)malloc(sizeof(BiThrNode)))) 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; } Status visit(TElemType e){ printf("%c\t",e); return OK; } Status InOrderTraverse_Thr(BiThrTree T,Status ( * visit)(TElemType e))//中序遍二叉递递递递 的非算法递递递递// { BiThrTree p; p=T->lchild; while(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; } void main() { BiThrTree T,Thrt; Thrt=(BiThrTree)malloc(sizeof(BiThrNode)); printf("按先序次序入二叉中点的,一个字符,,空格 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 示字符递递递递递递递递递递递递递递递递递递递递递递递\n"); CreatBiThrTree(T); printf("下面将此二叉中序索化递递递递递递\n"); InOrderThreading(Thrt,T); printf("下面中序遍索二叉递递递递递递递\n"); InOrderTraverse_Thr(Thrt,visit);}
本文档为【二叉树的先序递归建立,中序线索化,中序遍历】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_003124
暂无简介~
格式:doc
大小:17KB
软件:Word
页数:0
分类:生活休闲
上传时间:2017-09-27
浏览量:28