使用扩展二叉树的方法建立二叉树
来源:互联网 发布:淘宝里怎么分享 编辑:程序博客网 时间:2024/05/20 20:45
/************************************************************************* * > File Name: test.c > Author: ma6174 > Mail: ma6174@163.com > Created Time: Tue 19 Sep 2017 09:59:50 PM CST ************************************************************************/#include<stdio.h>#include<stdlib.h>#define ERROR 0#define OK 1typedef int Status;typedef char TElemType ;struct BiTNode{ TElemType data; struct BiTNode *lchild, *rchild;};void CreateBiTree(struct BiTNode **T){ TElemType ch; scanf("%c", &ch); if(ch == '#') *T = NULL; else { *T = (struct BiTNode*)malloc(sizeof(struct BiTNode)); if(*T == NULL) exit(EXIT_FAILURE); (*T)->data = ch;//生成根节点 CreateBiTree(&(*T)->lchild);//构造左子树 CreateBiTree(&(*T)->rchild); //构造右子树 }}struct BiTNode* CreateTree(void){ TElemType ch; struct BiTNode *node = NULL; scanf("%c", &ch); if(ch == '#') return NULL; else { node = (struct BiTNode*)malloc(sizeof(struct BiTNode)); if(node == NULL) exit(EXIT_FAILURE); node->data = ch;//生成根节点 node->lchild = CreateTree(); node->rchild = CreateTree(); return node; }}void PreOrderTraverse(struct BiTNode *tree){ if(tree == NULL) return; else { printf("%c ", tree->data); PreOrderTraverse(tree->lchild); PreOrderTraverse(tree->rchild); }}int main(void){ struct BiTNode *tree = CreateTree(); //CreateBiTree(&tree); PreOrderTraverse(tree); printf("\n"); return 0;}
阅读全文
0 0
- 使用扩展二叉树的方法建立二叉树
- 二叉树的建立(扩展二叉树法)
- 使用数组的方法建立一颗二叉树
- 二叉树的建立与遍历方法
- 二叉树的建立(多种方法)
- 二叉树的建立与遍历方法
- 二叉树的建立方法,你都懂吗?
- 二叉树的建立
- 二叉树的建立
- 二叉树的建立
- 二叉树的建立
- 二叉树的建立
- 二叉树的建立
- 二叉树的建立
- 二叉树的建立
- 二叉树的建立
- 【二叉树的建立】
- 二叉树的建立
- MySQL 5.6 --> 5.7 的升级
- win10里的控制面板里没有Realtek,前置耳机孔无法使用
- break语句和continue语句的区别
- BZOJ 3221: [Codechef FEB13] Obserbing the tree树上询问 树链剖分 主席树
- linux下R安装RMySQL不成功 configuration failed for package ‘RMySQL’
- 使用扩展二叉树的方法建立二叉树
- Mybatis学习与使用
- CV_EVENT_FLAG_LBUTTON 中flags代表拖拽事件
- java网络编程--IP与InetAddress
- SQL获取SQL Server 根据表名获取表的所有列及属性
- 复制当前日期前一天的所有文件源码
- ubantu(linux)构建开发环境(JDK/intellij idea/maven)
- Codeforces 852D Exploration plan(最短路+二分+二分图匹配)
- 【PostgreSQL-9.6.3】物化视图