设计二(二叉树上结点的路径)的代码
#include<stdio.h>
#include<stdlib.h>
#define MAX 100
#define ElemType char
#define right 1
#define error 0
typedef int Status;
typedef enum{Link,Thread} PointerTag;
int flag=0;
typedef struct BiTNode
{
ElemType data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
Status InitBitTree(BiTree &T)//构造空树
{
T=(BiTNode*)malloc(sizeof(BiTNode));
if(!T)
{
printf("构造空树时出错");
return error;
}
T->data =NULL;
T->lchild =NULL;
T->rchild =NULL;
return right;
}
Status Create(BiTree &T)//建立二叉链表
{
char ch;
printf("请输入结点的值(空用'#'): ");
scanf("%s",&ch);
if(ch=='#') T=NULL;
else
{
if(!(T=(BiTNode*)malloc(sizeof(BiTNode)))) return error;
T->data =ch;
Create(T->lchild);
Create(T->rchild);
评论1
最新资源