3341 資料結構實驗之二叉樹二 遍歷二叉樹

2021-08-10 03:44:21 字數 668 閱讀 8755

time limit: 1000ms

memory limit: 65536kb

problem description

已知二叉樹的乙個按先序遍歷輸入的字串行,如abc,,de,g,,f,,, (其中,表示空結點)。請建立二叉樹並按中序和後序的方式遍歷該二叉樹。

input

連續輸入多組資料,每組資料輸入乙個長度小於50個字元的字串。

output

每組輸入資料對應輸出2行:

第1行輸出中序遍歷序列;

第2行輸出後序遍歷序列。 

example input

abc,,de,g,,f,,,

example output

cbegdfacgefdba#include #include #include struct node

;char st[51];

int x;

struct node *creat()

else

return root;

}void zhongxu(struct node *root)

}void houxu(struct node *root)

}int main()

return 0;

}

3341 資料結構實驗之二叉樹二 遍歷二叉樹

3341 資料結構實驗之二叉樹二 遍歷二叉樹 time limit 1000ms memory limit 65536kb problem description 已知二叉樹的乙個按先序遍歷輸入的字串行,如abc,de,g,f,其中,表示空結點 請建立二叉樹並按中序和後序的方式遍歷該二叉樹。inpu...

資料結構實驗之二叉樹四 還原二叉樹

time limit 1000ms memory limit 65536k 給定一棵二叉樹的先序遍歷序列和中序遍歷序列,要求計算該二叉樹的高度。輸入資料有多組,每組資料第一行輸入1個正整數n 1 n 50 為樹中結點總數,隨後2行先後給出先序和中序遍歷序列,均是長度為n的不包含重複英文本母 區分大小...

資料結構實驗之二叉樹四 還原二叉樹

time limit 1000ms memory limit 65536k 有疑問?點這裡 給定一棵二叉樹的先序遍歷序列和中序遍歷序列,要求計算該二叉樹的高度。輸入資料有多組,每組資料第一行輸入 1個正整數 n 1 n 50 為樹中結點總數,隨後 2行先後給出先序和中序遍歷序列,均是長度為 n的不包...