迭代版的前序遍历,每输出一个元素,就要push一次;迭代版的中序遍历,每输出一个元素,就要pop一次。得到前序遍历和中序遍历的序列后,构造树,然后对树进行后序遍历。
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
using namespace std;
struct node {
int index;
node *left, *right;
};
node *insert(int index);
void postorder(node *root);
void deletetree(node *root);
node *rebuild(int