From 14e5dec9bede7f530f8f6a5b0d2295d767ace64f Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Sun, 12 Mar 2017 10:56:41 +0800 Subject: [PATCH] Create 1489_li_jun_09_05.cpp From http://www.tuicool.com/articles/MZZreaE From http://blog.csdn.net/li_jun_09_05/article/details/26407659 --- SDUTOJ/1489_li_jun_09_05.cpp | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 SDUTOJ/1489_li_jun_09_05.cpp diff --git a/SDUTOJ/1489_li_jun_09_05.cpp b/SDUTOJ/1489_li_jun_09_05.cpp new file mode 100644 index 0000000..c7fb956 --- /dev/null +++ b/SDUTOJ/1489_li_jun_09_05.cpp @@ -0,0 +1,53 @@ +#include +#include +#define MAX 50+3 +using namespace std; +typedef char Elem_Type; +typedef struct BiTree +{ + Elem_Type data;//数据 + struct BiTree *Lchild;//左孩子 + struct BiTree *Rchild;//右孩子 +}BiTree; //要查找的元素 查找的地方 数组的长度 +int Search_Num(Elem_Type num,Elem_Type *array,int len) +{ + for(int i=0; idata = *back; + int index = Search_Num(*back,center,len); + temp->Rchild = Resume_BiTree(center+index+1,back-1,len-index-1); + temp->Lchild = Resume_BiTree(center,back-len+index,index); + return temp; +} +void PreOrderTraverse(BiTree *root)//前序遍历 +{ + if( root != NULL) + { + cout<data; + PreOrderTraverse(root->Lchild); + PreOrderTraverse(root->Rchild); + } +} +int main(void) +{ + Elem_Type *inorder = new Elem_Type [MAX];//中序 + Elem_Type *postorde = new Elem_Type [MAX];//后序 + int t;cin>>t; + while(t--) + { + cin>>inorder;cin>>postorde; + BiTree *root = + Resume_BiTree(inorder,postorde+strlen(postorde)-1,strlen(inorder)); + PreOrderTraverse(root); + cout<