数据结构--二叉树
来源:互联网 发布:阿里云百度云加速 编辑:程序博客网 时间:2024/05/04 11:28
#include <stdio.h>#include <stdlib.h>typedef struct tree{ char data; struct tree * lc, * rc;}bit;void creat(bit * & );void inorder(bit * );//先序遍历int depth(bit * );int count(bit * );int main(void){ bit * root; creat(root); inorder(root); printf("\n%d\n", depth(root)); printf("%d\n", count(root)); return 0;}int count(bit * node){ if (node == NULL) return 0; else return count(node->lc) + count(node->rc) + 1;}int depth(bit * node){ int m, n; if (node == NULL) return 0; else { m = depth(node->lc); n = depth(node->rc); if (m > n) return m + 1; else return n + 1; }}void inorder(bit * node){ if (node) { printf("%c ", node->data); inorder(node->lc); inorder(node->rc); }}void creat(bit * &node){ char ch; scanf("%c", &ch); if (ch == '#') node = NULL; else { node = (bit * )malloc(sizeof(bit)); node->data = ch; creat(node->lc); creat(node->rc); }}
0 0
- 数据结构-树-二叉树
- 数据结构::树,二叉树
- 数据结构-二叉树
- 二叉树的数据结构
- 数据结构-二叉树算法
- java数据结构:二叉树
- 数据结构---二叉树
- 数据结构(C++)--二叉树
- JAVA 数据结构 二叉树
- 数据结构-二叉树 问题
- 转贴:数据结构:二叉树
- 二叉树(数据结构 c++)
- 数据结构-二叉树操作
- java数据结构----二叉树
- 数据结构二叉树
- 数据结构中的二叉树
- 数据结构--二叉树
- 数据结构二叉搜索树
- 哈理工 hrbust 1328 相等的最小公倍数
- Switch分支语句
- C++计算程序运行时间
- c++ 依次存放在指定范围内求出的所有素数
- 【前端开发】html | 01
- 数据结构--二叉树
- Eclipse下用NDK编译生成so文件
- Gooligan木马威胁谷歌的安全
- java中调用静态方法时候可以省略类名吗?
- SQl语句中使用占位符的优点
- Crypto
- 清空mysql命令历史记录
- JS中的prototype
- 关于国产项目Apache Kylin 发展历程及背后的那些事