二叉树的建树

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
char s[100000];
int flog=0;
struct tree
{
char a;
struct tree *left,*right;
}*head;
tree * great()
{
char k;
scanf("%c",&k);
tree *p1;
p1=(tree *)malloc(sizeof(tree));
if(k=='#')
{
p1=NULL;
}
else
{
p1->a=k;
p1->left=great();
p1->right=great();
}
return p1;
}

void pre(tree *p1)
{
if(p1)
{
printf("%c",p1->a);
pre(p1->left);
pre(p1->right);
}
// else printf("#");
}

void zhong(tree *p1)
{
if(p1)
{

zhong(p1->left);
printf("%c",p1->a);
zhong(p1->right);
}

}

void fun(tree *p1)
{
if(p1)
{

fun(p1->left);

fun(p1->right);
printf("%c",p1->a);
}
}

原文地址:https://www.cnblogs.com/woyaocheng/p/4948404.html