二叉树-顺序

来源:互联网 发布:李沙沙淘宝情趣内衣 编辑:程序博客网 时间:2024/05/15 23:44

/*二叉树-顺序*/

#include<stdio.h>
#define MAXSIZE 100
#define Telemtype int
#define Status void
typedef Telemtype sqbitree[MAXSIZE];
sqbitree bt;

/*构造一个二叉树,输入各结点的值的函数*/
Status createbitree(sqbitree *b)
{
 int i,num;
 printf("Input the bitree's node number: ");
 scanf("%d",&num);
 *b[0]=num;
 printf("/nInput the the %d data: ",num);
 for(i=1;i<=num;++i)
  scanf("%d",b[i]);    /*用0表示空树*/
}

/*遍历二叉树的函数*/
Status trave(sqbitree *b)
{
 int i;
 printf("The data of the bitree is:/n");
 for(i=1;i<=*b[0];++i)
 printf("%d  ",*b[i]);
 printf("/n");
}

void main()
{
createbitree(&bt);
trave(&bt);
}

原创粉丝点击