두 갈래 트리의 선행 및 중행 반복 시퀀스를 입력하고 이 두 갈래 트리의 후행 반복 시퀀스 __2018.07.15
1360 단어 고급 데이터 구조
#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 = *front;
int index = Search_Num(*front, center, len);
temp->Lchild = Resume_BiTree(front + 1, center, index);
temp->Rchild = Resume_BiTree(front + index + 1, center + index + 1, len - index - 1);
return temp;
}
void PostOrderTraverse(BiTree *root)//
{
if (root != NULL)
{
PostOrderTraverse(root->Lchild);
PostOrderTraverse(root->Rchild);
cout << root->data;
}
}
int main(void)
{
Elem_Type *preorder = new Elem_Type[MAX];//
Elem_Type *inorder = new Elem_Type[MAX];//
cin >> preorder;cin >> inorder;
BiTree *root = Resume_BiTree(preorder, inorder, strlen(inorder));
PostOrderTraverse(root);
cout << endl;
return 0;
}