有一棵以二叉链表存储的二叉树,求出二叉树的深度并输出所有叶子结点的值
typedef struct Bitnode //二叉树结点定义 { int data; struct Bitnode *lchild; struct Bitnode *rchild; }Bitnode; Bitnode* Binary_Create() //创建二叉树 { Bitnode *t = NULL; int n; scanf("%d", &n); if (n != 0) { t = (Bitnode *)malloc(sizeof(Bitnode)); if (t == NULL) ...全部
typedef struct Bitnode //二叉树结点定义 { int data; struct Bitnode *lchild; struct Bitnode *rchild; }Bitnode; Bitnode* Binary_Create() //创建二叉树 { Bitnode *t = NULL; int n; scanf("%d", &n); if (n != 0) { t = (Bitnode *)malloc(sizeof(Bitnode)); if (t == NULL) printf("内存分配错误!"); else { t->data = n; t->lchild = Binary_Create(); t->rchild = Binary_Create(); } } return t; } void Binary_Output(Bitnode *t) //前序遍历二叉树 { if (t != NULL) { printf("%d ", t->data); Binary_Output(t->lchild); Binary_Output(t->rchild); } } void Binary_Delete(Bitnode *t) //释放空间 { if (t != NULL) { Binary_Delete(t->lchild); Binary_Delete(t->rchild); free(t); } } void Inorder(Bitnode *t) //中序遍历 { if ( t != NULL) { Inorder(t->lchild); printf("%d ", t->data); Inorder(t->rchild); } }。
收起