pta 求二叉樹高度 10分)

2021-10-10 12:58:47 字數 878 閱讀 3803

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

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()

/ 你的**將被嵌在這裡 */

輸出樣例(對於圖中給出的樹):

有遞迴是最簡單的,演算法思想很簡單:

如果左子樹的深度大於右子樹,那麼就返回左子樹,同理,右子樹一樣道理。

這樣的話就完成了

int

getheight

( bintree bt )

求二叉樹高度PTA

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

4 12 求二叉樹高度 10 分

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

求二叉樹高度

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