代码写的比较乱,凑合看吧。
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
class node{
public:
int num;
node *left;
node *right;
public:
node(int n = 0){
num = n;
left = NULL;
right = NULL;
}
};
class Tree{
public:
node* root;
public:
Tree (node *n = NULL){
root = n;
if(n != NULL){
root->num = n->num;
root->left = n->left;
root->right = n->right;
}
}
};
vector<int> mid;
vector<int> rev;
typedef vector<int>::iterator ite;
ite creattree(node* nroot, ite rroot, ite mleft, ite mright){
nroot->num = *rroot;
ite mid = find(mleft, mright, *rroot);
ite bound = rroot;
if (mid != mright){
nroot->right = new node;
bound = creattree(nroot->right, rroot - 1, mid + 1, mright);
}
if ( mid != mleft){
nroot->left = new node;
bound = creattree(nroot->left, bound - 1, mleft, mid - 1);
}
return bound;
}
int main()
{
in