二叉树求叶子数、树的高度
来源:互联网 发布:linux常用命令cp 编辑:程序博客网 时间:2024/05/16 01:36
#include<stdio.h>#include<iostream>#include<algorithm>#include<stdlib.h>using namespace std;#define status inttypedef struct bitnode{char data;struct bitnode *lchild;struct bitnode *rchild;} bitnode,*sq;int r=0;bitnode *q;int num=0;int high=0;void createbitree(sq &T){char ch;scanf("%c",&ch);if(ch=='#')T=NULL;else{T=(bitnode *)malloc(sizeof(bitnode));T->data=ch;if(r==0){q=T;r=1;}createbitree(T->lchild);createbitree(T->rchild);}}void leafcount(sq &T){if(T!=NULL){if(T->lchild==NULL&&T->rchild==NULL)num++;leafcount(T->lchild);leafcount(T->rchild);}}status hightree(sq &T){int h1,h2,h;if(T==NULL)h=0;if(T!=NULL){h1=hightree(T->lchild);h2=hightree(T->rchild);h=(h1>h2?h1:h2)+1;}return h;}int main(){bitnode *t;printf("createbitree:");createbitree(t);t=q; printf("leafcount:");leafcount(t);printf("%d\n",num);printf("hightree:");printf("%d\n",hightree(t));}
阅读全文
0 0
- 二叉树求叶子数、树的高度
- 求二叉树的叶子结点数
- 求二叉树的叶子数
- 二叉树求叶子数
- 树与图的应用:二叉树的构造、遍历和求叶子数和高度
- 计算二叉树的高度、节点数、叶子节点数
- 递归遍历 二叉树 求高度 和 节点数 和 叶子节点数
- 求二叉树非叶子节点数
- 求二叉树中的叶子数
- C语言二叉树求叶子数
- 【算法导论】求二叉树的叶子数和深度
- 求二叉树的深度、宽度和叶子结点数
- 二叉树的创建,遍历,求高度,算出节点数,算出叶子节点数,左右子树的交换,二叉树的销毁。
- 求二叉树的叶子节点数目/二叉树的高度
- 二叉树求高度、叶子节点个数、总节点个数
- Java二叉树的递归,非递归遍历,高度,节点数,叶子节点数
- Java二叉树的递归,非递归遍历,高度,节点数,叶子节点数
- 求二叉树的前中后序递归、迭代,树的叶子节点,高度(c语言)
- 我为国内微积分“小糊涂”感到悲哀!
- 如何做数据分析
- css3 mix-blend-mode 混合模式详解
- jsp、freemarker、velocity 三者的区别与优缺点
- Mysql中用SQL增加、删除字段,修改字段名、字段类型、注释,调整字段顺序
- 二叉树求叶子数、树的高度
- android路由表操作
- Android不同平台版本
- Redis的缓存策略和主键失效机制
- 各种文件系统名词解释
- unity、程序开发必知的10大基础实用算法及其讲解
- java类集---Map使用注意事项
- dva + antd 初次使用
- Mac下intellij IDEA配置vue支持