problem description
已知一棵二叉樹的中序遍歷和後序遍歷,求二叉樹的先序遍歷
input
輸入資料有多組,第一行是乙個整數t (t<1000),代表有t組測試資料。每組包括兩個長度小於50 的字串,第乙個字串表示二叉樹的中序遍歷序列,第二個字串表示二叉樹的後序遍歷序列。
output
輸出二叉樹的先序遍歷序列
sample input
2sample outputdbgeafc
dgebfca
lnixu
linux
abdegcfhintxnliu
#includeusing namespace std;
struct node
;node *create(char *middle,char *finall,int len)
void previousshow(node *root)
}int main()
{ int t;
cin>>t;
while(t--)
{node *root;
char middle[100],finall[100];
cin>>middle>>finall;
int len=strlen(middle); //都一樣
root=create(middle,finall,len);//建立出二叉樹,然後再先序遍歷即可
previousshow(root);
coutgyx題解:根據中序和後序條件建立起二叉樹,先序遍歷即可。
先序建立二叉樹及先序 中序 後序遍歷
先序二叉樹 先序建立二叉樹 void createbitree bitree t t bitnode malloc sizeof bitnode t data cnt t lchild null t rchild null createbitree t lchild createbitree t r...
二叉樹先序 中序 後序遍歷
題目 用遞迴和非遞迴方式,分別按照二叉樹先序 中序和後序列印所有的節點。我們約定 先序遍歷順序為根 左 右 中序遍歷順序為左 根 右 後序遍歷順序為左 右 根。遞迴實現 遞迴遍歷二叉樹 先序 public void preorderrecur node head system.out.println...
中序後序,中序先序求二叉樹
用後序,中序求二叉樹 includeusing namespace std int n int a 105 b 105 mapl,r int build int la,int ra,int lb,int rb 再在中序中找到這個數的位置 if i rb return root queueq void...