資料結構實驗之二叉樹八 (中序後序)求二叉樹的深度

2021-08-23 14:08:15 字數 866 閱讀 8075

time limit: 1000 ms memory limit: 65536 kib

problem description

已知一顆二叉樹的中序遍歷序列和後序遍歷序列,求二叉樹的深度。

input

輸入資料有多組,輸入t,代表有t組資料。每組資料報括兩個長度小於50的字串,第乙個字串表示二叉樹的中序遍歷,第二個表示二叉樹的後序遍歷。

output

輸出二叉樹的深度。

sample input

2 dbgeafc

dgebfca

lnixu

linux

sample output4 3

**hint

source**

ps:先在後序遍歷中從後向前找到乙個根結點;再在中序遍歷中找到該結點,則中序遍歷中該結點左邊為左子樹,右邊為右子樹。依次迴圈。

#include 

#include

#include

typedef

struct node

bitnode;

bitnode *creat(int l,char hx,char zx)

root->l=creat(i,hx,zx);

root->r=creat(l-i-1,hx+i,zx+i+1);

return root;

}int high(bitnode *root)

int main()

return

0;}

資料結構實驗之二叉樹八 (中序後序)求二叉樹的深度

problem description 已知一顆二叉樹的中序遍歷序列和後序遍歷序列,求二叉樹的深度。input 輸入資料有多組,輸入t,代表有t組資料。每組資料報括兩個長度小於50的字串,第乙個字串表示二叉樹的中序遍歷,第二個表示二叉樹的後序遍歷。output 輸出二叉樹的深度。example in...

資料結構實驗之二叉樹八 (中序後序)求二叉樹的深度

time limit 1000ms memory limit 65536kb submit statistic problem description 已知一顆二叉樹的中序遍歷序列和後序遍歷序列,求二叉樹的深度。input 輸入資料有多組,輸入t,代表有t組資料。每組資料報括兩個長度小於50的字串,...

資料結構實驗之二叉樹八 (中序後序)求二叉樹的深度

time limit 1000ms memory limit 65536kb submit statistic problem description 已知一顆二叉樹的中序遍歷序列和後序遍歷序列,求二叉樹的深度。input 輸入資料有多組,輸入t,代表有t組資料。每組資料報括兩個長度小於50的字串,...