求二叉樹的高度

2021-08-10 08:43:41 字數 935 閱讀 1041

本題要求給定二叉樹的高度。

函式介面定義:

int getheight( bintree bt );
其中bintree結構定義如下:
typedef

struct tnode *position;

typedef position bintree;

struct tnode;

要求函式返回給定二叉樹bt的高度值。裁判測試程式樣例:

#include 

#include

typedef

char elementtype;

typedef

struct tnode *position;

typedef position bintree;

struct tnode;

bintree creatbintree(); /* 實現細節忽略 */

int getheight( bintree bt );

int main()

輸出樣例:

4
int getheight(bintree bt)

return height;

}

如何有效的利用遞迴是關鍵。求二叉樹的高度,求出在二叉樹子樹中的最高的高度,子樹高度+1就是二叉樹的高度。邊界值是樹為空,即樹的高度為0。

求二叉樹高度

函式介面定義 int getheight bintree bt 其中bintree結構定義如下 typedef struct tnode position typedef position bintree struct tnode 要求函式返回給定二叉樹bt的高度值。裁判測試程式樣例 include...

求二叉樹高度

本題要求給定二叉樹的高度。函式介面定義 int getheight bintree bt 其中bintree結構定義如下 typedef struct tnode position typedef position bintree struct tnode 要求函式返回給定二叉樹bt的高度值。裁判測...

求二叉樹高度

題目來自於pta 函式介面定義 int getheight bintree bt 其中bintree結構定義如下 typedef struct tnode position typedef position bintree struct tnode 要求函式返回給定二叉樹bt的高度值。裁判測試程式樣...