线索二叉树
来源:互联网 发布:淘宝店家开通蚂蚁花呗 编辑:程序博客网 时间:2024/06/07 00:59
头文件(线索二叉树结构体以及相关函数声明部分)
#ifndef TREAD#define THREADtypedef enum{link =0,thread =1} pointtag;typedef char elemtype;typedef struct bithrnode{bithrnode *leftchild;bithrnode *rightchild;pointtag ltag,rtag;elemtype data;}bithrnode,*bithetree;bithrnode *buynode();void freenode(bithrnode *ptr);bithrnode *createthr(char *&str);bithrnode *createthrtree(char *str);void inorder(bithrnode *ptr);void make(bithrnode *ptr,bithrnode *&p);void makethreadtree(bithrnode *ptr);bithrnode * first(bithrnode *p);bithrnode * next(bithrnode *p);void thrinorder(bithrnode *ptr);#endif
相关函数:
bithrnode *buynode(){bithrnode *s=(bithrnode *)malloc(sizeof(bithrnode));return s;}void freenode(bithrnode *ptr){free(ptr);}//ABC##DE##F##G#H##bithrnode *createthr(char *&str){bithrnode *s=NULL;if (*str!='#'){s=buynode();s->data=*str;s->ltag=s->rtag=link;s->leftchild=createthr(++str);s->rightchild=createthr(++str);}return s;}bithrnode *createthrtree(char *str){if (str==NULL){return NULL;}else{return createthr(str);}}void inorder(bithrnode *ptr){if (ptr!=NULL){inorder(ptr->leftchild);printf("%c ",ptr->data);inorder(ptr->rightchild);}}void makethreadtree(bithrnode *ptr){bithrnode *p=NULL;make(ptr,p);p->rightchild=NULL;p->rtag=thread;}void make(bithrnode *ptr,bithrnode *&p){if (ptr!=NULL){makethreadtree(ptr->leftchild);if (ptr->leftchild==NULL){ptr->leftchild=p;ptr->ltag=thread;}if (p!=NULL && p->rightchild==NULL){p->rightchild=ptr;p->rtag=thread;}p=ptr;makethreadtree(ptr->rightchild);}}bithrnode * first(bithrnode *p) {while(p!=NULL && p->ltag!=thread){p=p->leftchild;}return p;}bithrnode * next(bithrnode *p){if (p==NULL){return NULL;}if (p->rtag == thread){return p->rightchild;}else {return first(p->rightchild);}}void thrinorder(bithrnode *ptr){bithrnode *p=NULL;for (p=first(ptr);p!=NULL;p=next(p)){printf("%c",p->data);}printf("\n");}
阅读全文
0 0
- 线索二叉树 --->树
- 线索二叉树算法
- C#线索二叉树
- 线索二叉树
- C#线索二叉树
- 线索二叉树
- 线索二叉树
- 线索化二叉树
- 线索二叉树
- C#线索二叉树
- C#线索二叉树
- 线索二叉树
- 线索二叉树实例
- 线索二叉树
- 线索二叉树算法
- C++线索二叉树
- 线索二叉树
- 线索二叉树实现
- caffemodel的读取与修改
- SQL注入 -- 概念及其应用
- Hibernate提供的多种查询方式
- Docker 容器使用
- 2017秋招求职历程总结
- 线索二叉树
- java.lang.NoClassDefFoundError:com/sun/tools/javac/code/TypeTags
- 每日学习流水账
- jsp笔记
- 基于等价类的邮箱注册测试用例设计
- CSS@media查询
- 最小二乘法实现二维多传感器标定
- linux下安装scrpay框架
- Ignatius's puzzle HDU