資料結構實驗之二叉樹四 (先序中序)還原二叉樹

2021-10-10 02:46:55 字數 855 閱讀 6415

description

給定一棵二叉樹的先序遍歷序列和中序遍歷序列,要求計算該二叉樹的高度。

input

輸入資料有多組,每組資料第一行輸入1個正整數n(1 <= n <= 50)為樹中結點總數,隨後2行先後給出先序和中序遍歷序列,均是長度為n的不包含重複英文本母(區分大小寫)的字串。

output

輸出乙個整數,即該二叉樹的高度。

sample

input

abdfghiec

fdhgibeac

output

#include

using

namespace std;

typedef

struct node

tree;

char pre[55]

, mid[55]

;tree *

creat

(char

*pre,

char

*mid,

int len)

root-

>l =

creat

(pre +

1, mid, i)

; root-

>r =

creat

(pre + i +

1, mid + i +

1, len - i -1)

;return root;

}int

depth_bintree

(tree *root)

return de;

}int

main()

return0;

}

資料結構實驗之二叉樹四 (先序中序)還原二叉樹

time limit 1000ms memory limit 65536kb submit statistic problem description 給定一棵二叉樹的先序遍歷序列和中序遍歷序列,要求計算該二叉樹的高度。input 輸入資料有多組,每組資料第一行輸入1個正整數n 1 n 50 為樹中...

資料結構實驗之二叉樹四 (先序中序)還原二叉樹

time limit 1000ms memory limit 65536kb submit statistic problem description 給定一棵二叉樹的先序遍歷序列和中序遍歷序列,要求計算該二叉樹的高度。input 輸入資料有多組,每組資料第一行輸入1個正整數n 1 n 50 為樹中...

資料結構實驗之二叉樹四 (先序中序)還原二叉樹

time limit 1000ms memory limit 65536kb submit statistic problem description 給定一棵二叉樹的先序遍歷序列和中序遍歷序列,要求計算該二叉樹的高度。input 輸入資料有多組,每組資料第一行輸入1個正整數n 1 n 50 為樹中...