以孩子兄弟链表为存储结构,设计递归和非递归算法求树的深度
#include <stdio.h>
#include <stdlib.h>
#define maxsize 20
typedef struct Node
{
char data;
struct Node *firstchild,*nextsibling;
}Node,*BiTree;
int CreateBiTree(BiTree *T);
int TreeHeightRecur(BiTree T);
int TreeHeightCycl(BiTree T);
int Max(int a,int b);
int main()
{
BiTree *T;
T=(BiTree *)malloc(sizeof(BiTree));
CreateBiTree(T);
int h1,h2;
h1=TreeHeightRecur(*T);
h2=TreeHeightCycl(*T);
printf("%d %d\n",h1,h2);
return 0;
}
int CreateBiTree(BiTree *T)
{
fflush(stdin);
printf("please input the node data:");
char ch;
scanf("%c",&ch);
*T=(BiTree)malloc(sizeof(Node));
(*T)->data=ch;
char c;
fflush(stdin);
printf("Dose %c has children(y--yes,n--no):",ch);
scanf("%c",&c);
if(c=='y')
CreateBiTree(&(*T)->firstchild);
else
(*T)->firstchild=NULL;
fflush(s