求二叉樹的先序遍歷

2021-09-13 14:07:02 字數 994 閱讀 5473

time limit: 1000 ms memory limit: 65536 kib

submit

statistic

problem description

已知一棵二叉樹的中序遍歷和後序遍歷,求二叉樹的先序遍歷

input

輸入資料有多組,第一行是乙個整數t (t<1000),代表有t組測試資料。每組包括兩個長度小於50 的字串,第乙個字串表示二叉樹的中序遍歷序列,第二個字串表示二叉樹的後序遍歷序列。 

output

輸出二叉樹的先序遍歷序列

sample input

2

dbgeafc

dgebfca

lnixu

linux

sample output

abdegcf

xnliu

#includeusing namespace std;

typedef struct bitnode

*bitree;

char in[51], post[51];

bitree creat_bitree(char in, char post, int n)

bitree root;

int i;

root = (bitnode *)malloc(sizeof(bitree));

root-> data = post[n - 1];

for(i = 0; i < n; i++)

}root-> lchild = creat_bitree(in, post, i);

root-> rchild = creat_bitree(in + i + 1, post + i, n - i - 1);

return root;

}void preorder(bitree root)

}int main(void)

return 0;

}

求二叉樹的先序遍歷

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...