根据树的两种遍历序列求第三种遍历序列

本文不探讨仅凭先序和后序序列还原唯一树的情况,主要聚焦于二叉树遍历的理论知识。
摘要由CSDN通过智能技术生成

只知道先序序列和后序序列是无法求出唯一的树,所以不做讨论。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

struct BinaryTreeNode
{
	char c;
	BinaryTreeNode *lchild, *rchild;
	BinaryTreeNode()
	{
		lchild = NULL, rchild = NULL;
	}
};
struct BinaryTreeNode *root1,*root2;

char preorder[100], inorder[100], postorder[100];

void preSearch(BinaryTreeNode *root)   //先序遍历树
{
	if(root != NULL)
	{
		printf("%c", root->c);
		preSearch(root->lchild);
		preSearch(root->rchild);
	}
	return ;
}

void midSearch(BinaryTreeNode *root)   //中序遍历树
{
	if(root != NULL)
	{
		midSearch(root->lchild);
		printf("%c", root->c);
		midSearch(root->rchild);
	}
	return ;
}

void postSearch(BinaryTreeNode *root)  //后序遍历树
{
	if(root != NULL)
	{
		postSearch(root->lchild);
		postSearch(root->rchild);
		printf("%c&
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值