⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitree.txt

📁 一、需求分析 1、 根据输入
💻 TXT
字号:
#include <stdio.h> 
#include <malloc.h> 

typedef struct node{ 
int data; 
struct node *lchild,*rchild; 
}*Bitree,tree; 
基本操作:
Bitree create (Bitree t,int c); 
void print1(Bitree); 
void print2(Bitree); 
void print3(Bitree); 
int number=0; 
主程序和其他伪码:
void main() 
{ 
Bitree t=0,r; 
r=create (t,0); 
printf("前序排列 :"); 
print1 (r); 
printf("\n中序排列 :"); 
print2 (r); 
printf("\n后序排列 :"); 
print3 (r); 
printf("\n层次排列 :"); 
cengci (r); 

} 

Bitree create(Bitree t,int c) 
{ 
Bitree p,di; 
do{ 
scanf("%d",&c); 
if (t==0) 
{ 
t=(Bitree)malloc(sizeof(tree)); 
t->lchild=t->rchild=0; 
t->data=c; 
} 
else 
{ p=t; 
while(p!=0) 
{ 
di=p; 
if(c<(p->data)) 
p=p->lchild; 
else 
p=p->rchild; 
} 
if(c<(di->data)) 
{ 
Bitree NEWdi=(Bitree) malloc(sizeof(tree)); 
NEWdi->lchild=NEWdi->rchild=0; 
NEWdi->data=c; 
di->lchild=NEWdi; 
} 
else 
{ 
Bitree NEWdi=(Bitree) malloc(sizeof(tree)); 
NEWdi->lchild=NEWdi->rchild=0; 
NEWdi->data=c; 
di->rchild=NEWdi; 
} 
} 
++number; 
}while(c!=0); 
printf("叶子的数量:%d\n",number); 
return t; 
} 
void print1(Bitree t) 
{ 
if (t!=0) 
{ 
printf("%d ",t->data); 
print1(t->lchild); 
print1(t->rchild); 
} 
} 
void print2(Bitree t) 
{ 
if (t!=0) 
{ 
print2(t->lchild); 
printf("%d ",t->data); 
print2(t->rchild); 
} 
} 
void print3(Bitree t) 
{ 
if (t!=0) 
{ 
print3(t->lchild); 
print3(t->rchild); 
printf("%d ",t->data); 
} 
}

void cengci(Bitree t)
{{ typedef struct node{ 
	 Bitree *vec[20];
     int f,r; 
}sq; 
  sq q;
 q.f = 0;          
 q.r = 0;
printf("%d",t->data);
 
q.vec[q.r]=t;     
q.r=q.r+1;}
while(q.f<q.r){
   t=q.vec[q.f];
    q.f=q.f+1;
    if(t->lchild !=NULL){
        printf("%d",t->lchild->data);
        q.vec[q.r]=t->lchild;
        q.r=q.r+1; }
    if (t->rchild!=NULL) {
        printf("%d",t->rchild->data);
        q.vec[q.r]=t->rchild;
        q.r=q.r+1;  }                    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -