为什么我的结点数运行不出来
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct node
{
char data;
struct node *rchild;
struct node *lchild;
};
void preorder(struct node *p)//前序
{
if(p!=NULL)
{
printf("%c",p->data);
preorder(p->lchild);
preorder(p->rchild);
}
}
void inorder(struct node *p)//中序
{
if(p!=NULL)
{
inorder(p->lchild);
printf("%c",p->data);
inorder(p->rchild);
}
}
void postorder(struct node *p)//后序
{
if(p!=NULL)
{
postorder(p->lchild);
postorder(p->rchild);
printf("%c",p->data);
}
}
int nodecount(struct node *p)//计算这棵二叉树的节点个数
{
int count=0;
if(p==NULL)
return 0;
else
{
count++;
count=count+nodecount(p->lchild);
count=count+nodecount(p->rchild);
}
return count;
}
int main()
{
struct node *p1,*p2,*p3,*p4,*p5,*p6,*p7,*p8,*p9;
p1=(struct node*)malloc(sizeof(struct node));
p1->data='A';
p1->lchild=NULL;
p1->rchild=NULL;
p2=(struct node*)malloc(sizeof(struct node));
p2->data='B';
p2->lchild=NULL;
p2->rchild=NULL;
p3=(struct node*)malloc(sizeof(struct node));
p3->data='C';
p3->lchild=NULL;
p3->rchild=NULL;
p4=(struct node*)malloc(sizeof(struct node));
p4->data='D';
p4->lchild=NULL;
p4->rchild=NULL;
p5=(struct node*)malloc(sizeof(struct node));
p5->data='E';
p5->lchild=NULL;
p5->rchild=NULL;
p6=(struct node*)malloc(sizeof(struct node));
p6->data='F';
p6->lchild=NULL;
p6->rchild=NULL;
p7=(struct node*)malloc(sizeof(struct node));
p7->data='G';
p7->lchild=NULL;
p7->rchild=NULL;
p8=(struct node*)malloc(sizeof(struct node));
p8->data='H';
p8->lchild=NULL;
p8->rchild=NULL;
p9=(struct node*)malloc(sizeof(struct node));
p9->data='I';
p9->lchild=NULL;
p9->rchild=NULL;
p1->lchild=p2;
p1->rchild=p3;
p2->lchild=p4;
p2->rchild=p5;
p3->lchild=p6;
p5->lchild=p7;
p6->rchild=p8;
p7->rchild=p9;
printf("前序遍历:");
preorder(p1);
printf("\n");
printf("中序遍历;");
inorder(p1);
printf("\n");
printf("后序遍历:");
postorder(p1);
printf("\n");
printf("结点数为:");
nodecount(p1);
return 0;
}
你不打印它怎么出来?