博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
二叉树
阅读量:3965 次
发布时间:2019-05-24

本文共 934 字,大约阅读时间需要 3 分钟。

二叉树叶子结点算法

 

#include 
#include
typedef struct btnode /*定义结点类型*/ { char data; struct btnode *lchild,*rchild; }bitnode,*bitree;bitree createbitree() { bitree t; char ch; scanf("%c",&ch); if(ch==' ') t=NULL; else { t=malloc (sizeof(bitnode)); /*申请生成新的结点*/ t->data=ch; t->lchild=createbitree(); /*递归构造左子树*/ t->rchild=createbitree(); /*递归构造右子树*/ } return t; }int binodecount(bitree bt) { if(bt==NULL) return 0; else return(binodecount(bt->lchild)+binodecount(bt->rchild)+1); }int bileafcount(bitree bt) { if(bt==NULL) return 0; else if(bt->lchild==NULL || bt->rchild==NULL) return 1; /*若是叶子结点,则返回1*/ else return(bileafcount(bt->lchild)+bileafcount(bt->rchild));}void main(){ bitree bt1; printf("创建二叉树:\n"); bt1=createbitree(); printf("二叉树结点的个数为:"); printf("%d",binodecount(bt1)); printf("\n"); printf("二叉树叶子结点的个数为:"); printf("%d",bileafcount(bt1)); printf("\n");}

转载地址:http://djyki.baihongyu.com/

你可能感兴趣的文章
身份证的正确使用方法——非常重要的知识
查看>>
ExtJS & Ajax
查看>>
Tomcat在Windows下的免安装配置
查看>>
JMeter常用测试元件
查看>>
JMeter——使用技巧
查看>>
Hibernate 实体层设计--Table per subclass
查看>>
Ruby解决方案:The 'ffi' native gem requires installed build tools ; 含最新DevKit下载地址
查看>>
Python之操作MySQL数据库(二)
查看>>
简单介绍如何使用robotium进行自动化测试
查看>>
Python之操作XML文件
查看>>
eclipse+ADT 进行android应用签名详解
查看>>
Robotium只有apk文件例如Music.apk
查看>>
UI自动化测试框架对比(二)
查看>>
Selenium-webdriver系列教程(9)——如何操作select下拉框
查看>>
Selenium-webdriver系列教程(10)——如何智能的等待页面加载完成
查看>>
Robotium测试NotePad(一)
查看>>
Robotium测试NotePad(二) //测试添加文本
查看>>
ksh 多进程
查看>>
ksh 命令分隔符
查看>>
Linux 精萃
查看>>