给定级别的二叉树节点数 [英] Binary tree number of nodes with a given level

查看:53
本文介绍了给定级别的二叉树节点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个程序,该程序从二进制给出的特定级别计算节点数树.

I need to write a program that counts the number of nodes from a certain level given in binary tree.

我的意思是<节点数(int级){}>

I mean < numberofnodes(int level){} >

我尝试编写它没有成功,因为我不知道如何达到某个水平然后再去计算节点数.

I tried writing it without any success because I don't how to get to a certain level then go to count number of nodes.

推荐答案

使用递归函数执行此操作,该递归函数仅下降到特定级别.

Do it with a recursive function which only descends to a certain level.

这篇关于给定级别的二叉树节点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆