二叉树递归创建和递归遍历

/*tips:最后返回指针很重要 bt root=NULL;root=Create(root);*/
#include<iostream>
using namespace std;
typedef struct Btree
{
	char data;
	Btree *lchild,*rchild;
}Btree,*bt;
bt Create(bt T);
void DisplayTree(bt T);
void main()
{
	bt root=NULL;
	root=Create(root);
	DisplayTree(root);
}
bt Create(bt T)
{
	
	char ch;
	cin>>ch;
	if(ch=='#')
		T=NULL;
	else
	{
		T=new Btree;
		T->data=ch;
		T->lchild=Create(T->lchild);
		T->rchild=Create(T->rchild);
	}
	return T;
}
void DisplayTree(bt T)
{
	if(T!=NULL)
	{
		cout<<T->data<<'	';
		DisplayTree(T->lchild);
		DisplayTree(T->rchild);
	}
	
}

极简,专注,速度,极致
原文地址:https://www.cnblogs.com/simplelifestyle/p/3761931.html