#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
typedef struct node
{
char data;
struct node *lt, *rt;
} ST;
int flag, k;
char str[60];
void fput(ST *root)
{
if(!root)
return;
else
{
printf("%c", root->data);
fput(root->lt);
fput(root->rt);
}
}
void midput(ST *root)
{
if(!root)
return;
else
{
midput(root->lt);
printf("%c", root->data);
midput(root->rt);
}
}
void behput(ST *root)
{
if(!root)
return;
else
{
behput(root->lt);
behput(root->rt);
printf("%c", root->data);
}
}
void cengxu(ST *root)
{
ST *team[10000];
int head = 0, last = 0;
team[last++] = root;
while(head < last)
{
if(team[head])
{
printf("%c", team[head]->data);
team[last++] = team[head]->lt;
team[last++] = team[head]->rt;
}
head++;
}
}
void leaf(ST *root)
{
if(root)
{
if(!root->lt && !root->rt)
k++;
leaf(root->lt);
leaf(root->rt);
}
}
ST *fahcreat(int len, char *str1, char *str2)
{
ST *root;
int i;
if(len == 0)
return NULL;
root = (ST *)malloc(sizeof(ST));
root->data = str1[0];
for(i=0; i<len; i++)
if(str2[i] == root->data)
break;
root->lt = fahcreat(i, str1+1, str2);
root->rt = fahcreat(len-i-1, str1+i+1, str2+i+1);
return root;
}
ST *zhcreat(int len, char *str1, char *str2)
{
if(len <= 0)
return NULL;
ST *root;
root = (ST *)malloc(sizeof(ST));
root->data = str2[len - 1];
int p = strchr(str1, str2[len-1]) - str1;
root->lt = zhcreat(p, str1, str2);
root->rt = zhcreat(len-p-1, str1+p+1, str2+p);
return root;
}
int deep(ST *root)
{
int l = 0, r = 0;
int max;
if(root)
{
l = deep(root->lt);
r = deep(root->rt);
if(l > r)
max = l;
else
max = r;
return max + 1;
}
return 0;
}