SWUST数据结构--先序遍历创建二叉树的中序遍历

#include<iostream>
using namespace std;

struct Tree
{
	char data;
	Tree *l,*r;
};

void Init(Tree *&T)
{
	char str;
	cin>>str;
	if(str!='#')
	{
		T = new Tree;
		T->data=str;
		Init(T->l);
		Init(T->r);
	}
	else T=NULL;
}
void Dot(Tree *&T)
{
	if(T->l) Dot(T->l);
	if(T) cout<<T->data;
	if(T->r) Dot(T->r);
	
}
int main()
{
	Tree *T;
	Init(T);
	Dot(T);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41681743/article/details/80033015