有无佬看看是哪里写错了,为什么我尝试输出二叉树输出不了呢
#ifndef COM_H
#define COM_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MaxSize 50
typedef char elemtype;
typedef struct node
{
elemtype data;
struct node *left;
struct node *right;
}BTNode;
void CreateBTree(BTNode * b,char * str)
{
BTNode * St[MaxSize],*p;
int top = -1,k,j=0;
char ch;
b = NULL;
ch = str[j];
while(ch!='\0')
{
switch (ch)
{
case '(':
top++;
St[top] = p;
k=1;
break;
case ')':
top--;
break;
case ',':
k=2;
break;
default:
p=(BTNode *)malloc(sizeof(BTNode));
p->data=ch;
p->left=p->right=NULL;
if(b==NULL)
b=p;
else
{
switch (k) {
case 1:
St[top]->left=p;
break;
case 2:
St[top]->right=p;
break;
}
}
}
j++;
ch=str[j];
}
}
void DestroyBTree(BTNode*b)
{
if(b!=NULL)
{
DestroyBTree(b->left);
DestroyBTree(b->right);
free(b);
}
}
BTNode *FindNode(BTNode*b,elemtype x)
{
BTNode * p;
if(b==NULL)
return NULL;
else if(b->data==x)
return b;
else
{
p=FindNode(b->left,x);
if(p!=NULL)
return p;
else
return FindNode(b->right,x);
}
}
BTNode *LchildNode(BTNode * p)
{
return p->left;
}
BTNode *RchildNode(BTNode * p)
{
return p->right;
}
int BTHeight(BTNode *b)
{
int left,right;
if(b==NULL)
return(0);
else
{
left = BTHeight(b->left);
right = BTHeight(b->right);
return (left>right)?(left+1):(right+1);
}
}
void DispBTree(BTNode *b)
{
if(b!=NULL)
{
printf("%c",b->data);
if(b->left!=NULL||b->right!=NULL)
{
printf("(");
DispBTree(b->left);
if(b->right!=NULL)
printf(",");
DispBTree(b->right);
printf(")");
}
}
}
void PreOrder(BTNode *b)
{
if(b!=NULL)
{
printf("%c",b->data);
PreOrder(b->left);
PreOrder(b->right);
}
}
void InOreder(BTNode *b)
{
if(b!=NULL)
{
InOreder(b->left);
printf("%c",b->data);
InOreder(b->right);
}
}
void PostOrder(BTNode *b)
{
if(b!=NULL)
{
PostOrder(b->left);
PostOrder(b->right);
printf("%c",b->data);
}
}
#endif