中、后序遍历用于构建二叉树
发布时间
阅读量:
阅读量
又中序遍历和后序遍历还原二叉树
通过分析一棵二叉树的中序与先序遍历结果,可以唯一地重建该树的结构。
题目要求:
编写一个程序,依据二叉树的先根序列和中根序列,构建一棵采用左右指针表示的二叉树。
例如:先根序列为 ABDGCEF#,中根序列为 DGBAECF#(#代表结束符号)。随后利用该程序生成对应的二叉树结构。
思路:

MY CODE
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
using namespace std;
string preorder = "";
string inorder = "";
//node of binary tree
struct Node{
char val;
Node *left, *right;
};
//display an binary tree by post
全部评论 (0)
还没有任何评论哟~
