最大功能c树高 [英] max function c tree height

查看:66
本文介绍了最大功能c树高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c中是否有一个max函数,所以我可以做这样的事情来计算树的高度 :或者也许有更好的方法来计算树高.

is there a max function in c so i can do something like this to calculate tree height :or perhaps there is a better way to calculate tree height.

int height(struct node *tree)
{ 
    if (tree == NULL) return 0;
    return 1 + max(height (tree->left), height (tree->right)); 
}

如果需要的话,我需要什么?

if so what includes do i need?

当前我收到此错误:

dict-tree.o:在函数"height"中:
/home/ex10/dict-tree.c:36:未定义对"max"的引用

dict-tree.o: In function 'height':
/home/ex10/dict-tree.c:36: undefined reference to `max'

推荐答案

可能是因为max是未定义的函数,

Probably because max is an undefined function,

尝试先实施max,然后再继续.

try implementing max first before proceeding.

int max(int a, int b) {
    if(a > b) return a;
    else return b;
}

这篇关于最大功能c树高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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