#include <bits/stdc++.h>
using
namespace
std;
struct
Tree {
int
val;
Tree* leftchild;
Tree* rightchild;
Tree(
int
_val, Tree* _leftchild, Tree* _rightchild)
{
val = _val;
leftchild = _leftchild;
rightchild = _rightchild;
}
};
struct
Tree* createBinaryTree(
int
post[],
bool
isLeaf[],
int
& n)
{
if
(n < 0){
return
NULL;
}
struct
Tree* root =
new
Tree(post[n], NULL, NULL);
bool
isInternalNode = !isLeaf[n];
n--;
if
(isInternalNode) {
root->rightchild = createBinaryTree(post, isLeaf, n);
root->leftchild = createBinaryTree(post, isLeaf, n);
}
return
root;
}
void
inorder(
struct
Tree* root)
{
if
(root == NULL){
return
;
}
inorder(root->leftchild);
cout << root->val <<
" "
;
inorder(root->rightchild);
}
int
main()
{
int
post[] = { 40, 20, 50, 60, 30, 10 };
bool
isLeaf[] = {
true
,
false
,
true
,
true
,
false
,
false
};
int
n =
sizeof
(post) /
sizeof
(post[0]) - 1;
struct
Tree* root = createBinaryTree(post, isLeaf, n);
inorder(root);
return
0;
}