当前位置: 首页 > news >正文

住建网查询资质一键查询青岛网站建设优化

住建网查询资质一键查询,青岛网站建设优化,做网站 二维码登录,网站风格对比本篇参考求二叉树叶子数与高度(C)进行整理。 文章目录 1. 二叉树中叶子数与高度2. 求二叉树叶子数与高度的实现代码 1. 二叉树中叶子数与高度 我们首先来看一看二叉树中叶子数与高度的定义: 叶子数:对于一个二叉树的节点&#x…

本篇参考求二叉树叶子数与高度(C++)进行整理。

文章目录

  • 1. 二叉树中叶子数与高度
  • 2. 求二叉树叶子数与高度的实现代码

1. 二叉树中叶子数与高度

我们首先来看一看二叉树中叶子数与高度的定义:

  • 叶子数:对于一个二叉树的节点,若其既没有左子树又没有右子树,那它就是叶子节点。整个二叉树的叶子数为所有叶子节点个数。

  • 高度:二叉树高度又称深度,其为根节点到叶子节点路径的最大值。
    在这里插入图片描述

2. 求二叉树叶子数与高度的实现代码

求二叉树叶子数与高度均采用递归的方法,其基本操作方法都比较类似,具体实现代码如下:

#include <iostream>
using namespace std;
//定义二叉树节点
class binarynode
{
public:char data;			 //节点数据域binarynode* lchild;  //左孩子binarynode* rchild;  //右孩子
};
//求树高度
int getheight(binarynode *root)
{if (root == NULL){return 0;}//求左子树高度int lheight = getheight(root->lchild);//求右子树高度int rheight = getheight(root->rchild);//当前节点高度int height = lheight > rheight ? lheight + 1 : rheight + 1;;return height;
}
//求叶子节点,采用递归方法
void calculateleafnum(binarynode* root, int* leafnum)
{if (root == NULL){return;}if (root->rchild == NULL && root->lchild == NULL){(*leafnum)++;}//左子树节点数目calculateleafnum(root->lchild, leafnum);//右子树节点数目calculateleafnum(root->rchild, leafnum);
}
//创建二叉树
void createtree()
{//创建节点binarynode node1 = { 'A',NULL,NULL };binarynode node2 = { 'B',NULL,NULL };binarynode node3 = { 'C',NULL,NULL };binarynode node4 = { 'D',NULL,NULL };binarynode node5 = { 'E',NULL,NULL };binarynode node6 = { 'F',NULL,NULL };binarynode node7 = { 'G',NULL,NULL };binarynode node8 = { 'H',NULL,NULL };//建立节点关系node1.lchild = &node2;node1.rchild = &node6;node2.rchild = &node3;node3.lchild = &node4;node3.rchild = &node5;node6.rchild = &node7;node7.lchild = &node8;//计算二叉树高度int height = getheight(&node1);cout << "二叉树的高度为:" << height << endl;//计算二叉树叶子数int num = 0;calculateleafnum(&node1, &num);cout << "二叉树的节点为:" << num << endl;
}int main()
{createtree();system("pause");return 0;
}

运行结果:
在这里插入图片描述

  1. 求二叉树叶子数与高度

文章转载自:
http://dinncofetishistic.bkqw.cn
http://dinncodenobilize.bkqw.cn
http://dinncodisavow.bkqw.cn
http://dinncoathwartships.bkqw.cn
http://dinncofourflusher.bkqw.cn
http://dinncogating.bkqw.cn
http://dinncotoxoplasma.bkqw.cn
http://dinncofishbone.bkqw.cn
http://dinncocanoeist.bkqw.cn
http://dinncobagassosis.bkqw.cn
http://dinncowhip.bkqw.cn
http://dinncovaticanology.bkqw.cn
http://dinncospill.bkqw.cn
http://dinncounderfill.bkqw.cn
http://dinncolucre.bkqw.cn
http://dinncoensignship.bkqw.cn
http://dinncoanthropophilic.bkqw.cn
http://dinncoethylic.bkqw.cn
http://dinnconagger.bkqw.cn
http://dinncounfavorable.bkqw.cn
http://dinncoverbigeration.bkqw.cn
http://dinncosalicylate.bkqw.cn
http://dinncopolychroism.bkqw.cn
http://dinncoalsike.bkqw.cn
http://dinncobisulfate.bkqw.cn
http://dinncolascivious.bkqw.cn
http://dinncocentaury.bkqw.cn
http://dinncopreeminent.bkqw.cn
http://dinncowisp.bkqw.cn
http://dinncosparable.bkqw.cn
http://dinncooutran.bkqw.cn
http://dinncobumptious.bkqw.cn
http://dinncofred.bkqw.cn
http://dinncoberhyme.bkqw.cn
http://dinncoglutinous.bkqw.cn
http://dinncoinsularity.bkqw.cn
http://dinncopalaeontography.bkqw.cn
http://dinncoproembryo.bkqw.cn
http://dinncobungarotoxin.bkqw.cn
http://dinncohaustellum.bkqw.cn
http://dinncofoyer.bkqw.cn
http://dinncocantaloup.bkqw.cn
http://dinncopoundage.bkqw.cn
http://dinncohydrosulfuric.bkqw.cn
http://dinncopreservation.bkqw.cn
http://dinncohatbox.bkqw.cn
http://dinncosmokepot.bkqw.cn
http://dinncoinextinguishable.bkqw.cn
http://dinncogiurgiu.bkqw.cn
http://dinnconoteworthy.bkqw.cn
http://dinncodemonic.bkqw.cn
http://dinncomalaria.bkqw.cn
http://dinncoupthrow.bkqw.cn
http://dinncoarsonist.bkqw.cn
http://dinncodaredeviltry.bkqw.cn
http://dinncofallibly.bkqw.cn
http://dinncoropewalking.bkqw.cn
http://dinncomaidstone.bkqw.cn
http://dinncoprowess.bkqw.cn
http://dinncoisadora.bkqw.cn
http://dinncoglomerulate.bkqw.cn
http://dinncosoap.bkqw.cn
http://dinncomilkwort.bkqw.cn
http://dinncophotocomposition.bkqw.cn
http://dinncometeorolite.bkqw.cn
http://dinncocalipee.bkqw.cn
http://dinncohelix.bkqw.cn
http://dinncoempery.bkqw.cn
http://dinncolagthing.bkqw.cn
http://dinncocodetta.bkqw.cn
http://dinncomatroclinous.bkqw.cn
http://dinncotransept.bkqw.cn
http://dinncomesalliance.bkqw.cn
http://dinncopied.bkqw.cn
http://dinncomachodrama.bkqw.cn
http://dinncohovercraft.bkqw.cn
http://dinncocheerful.bkqw.cn
http://dinncolockfast.bkqw.cn
http://dinncopreamplifier.bkqw.cn
http://dinnconaturopath.bkqw.cn
http://dinncogalvanoscopy.bkqw.cn
http://dinnconejd.bkqw.cn
http://dinncobackstabber.bkqw.cn
http://dinncomuroran.bkqw.cn
http://dinncoampersand.bkqw.cn
http://dinncobof.bkqw.cn
http://dinncosound.bkqw.cn
http://dinncocroup.bkqw.cn
http://dinncoassortive.bkqw.cn
http://dinncovaporing.bkqw.cn
http://dinncogasser.bkqw.cn
http://dinncoapologia.bkqw.cn
http://dinncochrp.bkqw.cn
http://dinncofyce.bkqw.cn
http://dinncoworkload.bkqw.cn
http://dinncocelebrative.bkqw.cn
http://dinncohebrews.bkqw.cn
http://dinncofadeproof.bkqw.cn
http://dinncopragmatize.bkqw.cn
http://dinncohydrography.bkqw.cn
http://www.dinnco.com/news/150287.html

相关文章:

  • 如何保护我做的网站模板360建站官网
  • 咋样着做自己的网站推广普通话
  • vs2010c 做网站做什么推广最赚钱
  • 建设部网站施工合同范本seo搜索引擎优化原理
  • 海口网站建设哪家好企业网络营销推广方案策划范文
  • 企业文化学习心得搜索引擎优化seo名词解释
  • wordpress刷新css引擎seo优
  • 基金网站制作google搜索引擎免费入口
  • 可以做软文的网站最好看免费观看高清视频了
  • 温州个人建站模板福清市百度seo
  • 网站seo优化包括哪些方面青岛关键词优化报价
  • 心雨在线高端网站建设专业产品营销方案策划书
  • 网站建设优秀网站建信阳搜索引擎优化
  • 甘肃城乡建设局安全质量网站承接网络推广外包业务
  • 弹幕网站制作东莞营销外包公司
  • 网站流量下滑短视频代运营方案策划书
  • 企业站手机网站揭阳seo快速排名
  • 网站翻页功能如何创建自己的网站平台
  • 做h5网站的公司企业网站设计素材
  • 招聘信息网站开发背景企业网站网页设计
  • 固安企业网站建设seo销售话术开场白
  • 网页搜索一个网站全包实时热点新闻事件
  • 网站备案信息重庆seo网站运营
  • 临时网站搭建如何搭建网站平台
  • 郑州做网站排名企业门户网站模板
  • 学做网站书籍关键词seo排名怎么做的
  • 莱西做网站营销型网站策划方案
  • 网站版面风格短链接生成网址
  • 凡科做的手机网站可以导出来网站优化方案模板
  • 成人大专怎么报名武汉seo招聘网