问题描述
- 求各位哥哥姐姐帮帮忙啊,这个程序哪里错了
-
#include
#include
typedef struct Binnode
{
char data;
struct Binnode lchild;
struct Binnode *rchild;
};
typedef Binnode *Bintree ;
typedef struct stack
{
Bintree data[100];
int flag[100];
int top;
};
typedef struct queue
{
Bintree data[30];
int front;
int rear;
};
void Creat_Bintree(Bintree *root)
{
char ch;
if((ch=getchar())==' ')
{
*root=NULL;
}
else
{
*root=(Binnode)malloc(sizeof(Binnode));
(*root)->data=ch;
Creat_Bintree(&(*root)->lchild);
Creat_Bintree(&(*root)->rchild);
}
}
void Preorder1(Bintree t)
{
if(t!=NULL)
{
printf("%c",t->data);
Preorder1(t->lchild);
Preorder1(t->rchild);
}
}
void Inorder1(Bintree t)
{
if(t!=NULL)
{
Inorder1(t->lchild);
printf("%c",t->data);
Inorder1(t->rchild);
}
}
void Posorder1(Bintree t)
{
if(t!=NULL)
{
Posorder1(t->lchild);
Posorder1(t->rchild);
printf("%c",t->data);
}
}
void Levelorder(Bintree t)
{
queue q;
q.data[0]=t;
q.front=0;q.rear=1;
printf("层次遍历二叉树结果:");
while(q.front
{
if(q.data[q.front])
{
printf("%c",q.data[q.front]->data);
q.data[q.rear++]=q.data[q.front]->lchild;
q.data[q.rear++]=q.data[q.front]->rchild;
q.front++;
}
else
{
q.front++;
}
}
printf("nn");
}
#include"Bintree.h"
void Exchange1(Bintree t)
{
Bintree temp;
if(t)
{
Exchange1(t->lchild);
Exchange1(t->rchild);
temp=t->lchild;
t->lchild=t->rchild;
t->rchild=temp;
}
}
#include"Bintree.h"
int Leaves_Num1(Bintree t)
{
if(t)
{
if(t->lchild==NULL&&t->rchild==NULL)
{
return 1;
}
return Leaves_Num1(t->lchild)+Leaves_Num1(t->rchild);
}
return 0;
}
int main()
{
int count=0;
Bintree t;
Creat_Bintree(&t);
count=Leaves_Num2(t);
printf("该二叉树的叶子结点数为:%dn",count);
return 0;
}
时间: 2024-11-07 11:57:50