求二叉樹的先序遍歷
time limit: 1000 ms memory limit: 65536 kib
submit statistic
problem description
已知一棵二叉樹的中序遍歷和後序遍歷,求二叉樹的先序遍歷
input
輸入資料有多組,第一行是乙個整數t (t<1000),代表有t組測試資料。每組包括兩個長度小於50 的字串,第乙個字串表示二叉樹的中序遍歷序列,第二個字串表示二叉樹的後序遍歷序列。
output
輸出二叉樹的先序遍歷序列
sample input
2dbgeafc
dgebfca
lnixu
linux
sample output
abdegcf
xnliu
hint
source
gyx**:
#include
#include
#include
struct node
;char a[55]
,b[55];
struct node *
creat
(char a,
char b,
int len)
t=(struct node *
)malloc
(sizeof
(struct node));
//開空間
t->data=b[len-1]
;//這兩步的位置寫錯,不應寫在下面的迴圈裡面
for(i=
0;i) t->lson=
creat
(a,b,i)
; t->rson=
creat
(a+i+
1,b+i,len-i-1)
;return t;
}void
firstshow
(struct node *t)
}int
main()
return0;
}
求二叉樹的先序遍歷
time limit 1000ms memory limit 65536k 已知一棵二叉樹的中序遍歷和後序遍歷,求二叉樹的先序遍歷 輸入資料有多組,第一行是乙個整數t t 1000 代表有t組測試資料。每組包括兩個長度小於50 的字串,第乙個字串表示二叉樹的中序遍歷序列,第二個字串表示二叉樹的後序遍...
求二叉樹的先序遍歷
time limit 1000ms memory limit 65536k 有疑問?點這裡 已知一棵二叉樹的中序遍歷和後序遍歷,求二叉樹的先序遍歷 輸入資料有多組,第一行是乙個整數t t 1000 代表有t組測試資料。每組包括兩個長度小於50 的字串,第乙個字串表示二叉樹的中序遍歷序列,第二個字串表...
求二叉樹的先序遍歷
已知一棵二叉樹的中序遍歷和後序遍歷,求二叉樹的先序遍歷 輸入資料有多組,第一行是乙個整數t t 1000 代表有t組測試資料。每組包括兩個長度小於50 的字串,第乙個字串表示二叉樹的中序遍歷序列,第二個字串表示二叉樹的後序遍歷序列。輸出二叉樹的先序遍歷序列 2 dbgeafc dgebfca lni...