点击(此处)折叠或打开
- /*
- *二叉树采用二叉链表结构表示。设计并实现如下算法:
- *求一棵二叉树的深度和双分支结点的个数。
- */
- #include <stdio.h>
- #include <stdlib.h>
- #define ERROR 0
- #define OK 1
- #define OVERFLOW 0
- #define STACK_INIT_SIZE 100
- #define STACKINCREMENT 100
- typedef char TElemType;
- typedef struct BiTNode {
- TElemType data;
- struct BiTNode *lchild, *rchild;
- }BiTNode, *BiTree;
- typedef BiTree ElemType;
- typedef struct {
- ElemType *base;
- ElemType *top;
- int stacksize;
- }SqStack;
- int InitStack (SqStack *S)
- {
- S->base=(ElemType *)malloc(STACK_INIT_SIZE * sizeof(ElemType));
- if (!S->base)
- exit (OVERFLOW);
- S->top=S->base;
- S->stacksize=STACK_INIT_SIZE;
- return OK;
- }
- int StackEmpty (SqStack S)
- {
- if (S.base==S.top)
- return 1;
- else
- return 0;
- }
- int Push (SqStack *S, ElemType e)
- {
- if (S->top - S