| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
 Reworld，下班在家制作游戏，1500万奖金等你拿 千里之行 始于足下

问题点数：0  回复次数：0

#include
#include
typedef struct Node
{
char data;
struct Node*LChild;
struct Node*RChild;
}BiTNode,*BiTree;
void CreateBiTree(BiTree *bt)
{
char ch;
ch=getchar( );
if(ch=='.')*bt=NULL;
else
{
*bt=(BiTree)malloc(sizeof(Node));
(*bt)->data=ch;
CreateBiTree(&((*bt)->LChild));
CreateBiTree(&((*bt)->RChild));
}
}
void PreOrder(BiTree root)
{
if(root!=NULL)
{
printf("%c",root->data);
PreOrder(root->LChild);
PreOrder(root->RChild);
}
}
void InOrder(BiTree root)
{
if(root!=NULL)
{
InOrder(root->LChild);
printf("%c",root->data);
InOrder(root->RChild);
}
}
void PostOrder(BiTree root)
{
if(root!=NULL)
{
PostOrder(root->LChild);
PostOrder(root->RChild);
printf("%c",root->data);
}
}
void PreTreeDepth(BiTree bt,int h)

{ int depth=0;
if(bt!=NULL)
{
if(h>depth) depth=h;
PreTreeDepth(bt->LChild,h+1);
PreTreeDepth(bt->RChild,h+1);
}
}
void leaf(BiTree root)

{   int LeafCount=0;
if(root!=NULL)
{
leaf(root->LChild);
leaf(root->RChild);
if(root->LChild==NULL&&root->RChild ==NULL)
LeafCount++;
}
}
void mainscreen()
{
printf("\n=========第三次实验--树与二叉树操作============");
printf("\n===============================================");
printf("\n==1.生成二叉树                               ==");
printf("\n==2.先序遍历                                 ==");
printf("\n==3.中序遍历                                 ==");
printf("\n==4.后序遍历                                 ==");
printf("\n==5.二叉树的深度                             ==");
printf("\n==6.二叉树中叶子结点数                       ==");
printf("\n==7.创建哈夫曼树                             ==");
printf("\n==8.哈夫曼编码                               ==");
printf("\n==0.退出                                     ==");
printf("\n===============================================\n");
printf("\n请输入你的选择：");
}
void main(){
CreateBiTree(&bt);
PreOrder(t);
InOrder(t);
InOder(t);
}

• 1
• 1/1页
• 1

Powered by Discuz, Processed in 0.070084 second(s), 7 queries.