二叉树深度与宽度
来源:互联网 发布:noteshelf软件功能 编辑:程序博客网 时间:2024/06/07 16:40
#include "OJ.h"
#include <string.h>
#include <stdio.h>
/*
Description
给定一个二叉树,获取该二叉树的宽度深度。
Prototype
int GetBiNodeInfo(BiNode &head, unsigned int *pulWidth, unsigned int *pulHeight)
Input Param
head 需要获取深度的二叉树头结点
Output Param
pulWidth 宽度
pulHeight 高度
Return Value
0 成功
1 失败或其他异常
*/
int getwidth(BiNode *head)
{
if(head==NULL)
return 0;
if(head->left==NULL&&head->right==NULL)
return 1;
int wideleft=getwidth(head->left);
int wideright=getwidth(head->right);
return wideleft+wideright;
}
int getheight(BiNode *head)
{
if(head==NULL)//深度只有0
return 0;
int leftdep=getheight(head->left);
int rightdep=getheight(head->right);
return leftdep>rightdep?(leftdep+1):(rightdep+1);
}
int GetBiNodeInfo(BiNode &head, unsigned int *pulWidth, unsigned int *pulHeight)
{
/*在这里实现功能*/
if(!pulWidth||!pulHeight)
return -1;
*pulWidth=getwidth(&head);
*pulHeight=getheight(&head);
return 0;
}
0 0
- 二叉树深度与宽度
- 二叉树深度和宽度
- [数据结构]求二叉树的深度与宽度
- 求二叉树的最大深度与最大宽度
- codevs1501 二叉树的最大宽度与深度
- 求二叉树的深度和宽度
- 求二叉树的深度和宽度
- 二叉树的最大深度和宽度
- 计算二叉树的深度和宽度
- 二叉树的深度和宽度
- 求二叉树的深度和宽度
- 求二叉树的深度和宽度
- 二叉树的宽度和深度
- 求二叉树的深度和宽度
- 二叉树的深度和宽度
- 二叉树学习笔记-深度和宽度
- 二叉树的宽度和深度
- 求二叉树的深度和宽度
- 显示和隐藏元素display&&visibility
- hdu 1394 Minimum Inversion Number 线段树求逆序数
- 【zTree】修改节点图标
- hdu 4901 The Romantic Hero
- 再论mysql线程出现Waiting for table flush被hang住问题
- 二叉树深度与宽度
- 老曹的忧郁
- NoSql入门和概述
- TableView的优化
- 简明adb使用教程
- Objective-C语法学习归纳
- 二维数组列排序
- 游戏编程模式:前言(架构,性能和游戏)(Part II)
- USACO 2015 US OPEN CONTEST,Gold Division Solution