PTA 函式題 求二叉樹高度(C語言)

2021-10-10 20:16:58 字數 992 閱讀 3625

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

函式介面定義:

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

;/* 實現細節忽略 */

intgetheight

( bintree bt )

;int

main()

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

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

4
函式如下:

int

getheight

(bintree bt)

a=getheight

(bt->left)+1

; b=

getheight

(bt->right)+1

;return a>b?a:b;

//若a>b,返回a,否則返回b。

}

求二叉樹高度PTA

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

6 1 求二叉樹高度 20分 PTA 函式題

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

(二叉樹基礎題)求二叉樹高度

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