在实现二叉树的顺序存储的过程中,遇到了一些问题,现记录如下:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define MAXSIZE 100/*存储空间初始分配量*/
#define MAX_TREE_SIZE 100/*定义树的最大节点数*/
typedef int status;
typedef int elemtype;
typedef struct position {
int level;
int order;
} position;
typedef elemtype sqbitree[MAXSIZE];
elemtype null=0;/*设0表示空*/
status visit(elemtype c) {
printf("%d ",c);
return OK;
}
status initbitree(sqbitree T) {
int i=0;
for(i=0; i<MAX_TREE_SIZE; i++)
T[i]=null;/*初始化时将所有节点置为空*/
return OK;
}
/*创建二叉树*/
status createbitree(sqbitree T) {
int i=0;
printf("请按层序输入结点的值(整型),0表示空结点,输999结束。结点数≤%d:\n",MAX_TREE_SIZE);
while(i<10) {
T[i]=i+1;
/*T[(i+1)/2-1]是T[i]的双亲节点*/
if(i&&!T[(i+1)/2-1]&&T[i]) {
printf("产生了没有双亲节点的新节点\n");
return ERROR;
}
i++;
}
/*其余节点置空*/
while(i<MAX_TREE_SIZE) {
T[i]=null;
i++;
}
return OK;
}
/*判断二叉树为空*/
status emptybitree(sqbitree T) {
if(!T[0])
return TRUE;
else