c 跨函数 用指针申请内存
static int _getCount(BiTree T)
{
if (NULL == T)
return 0;
return getCount(T->lchild) + getCount(T->rchild) + 1;
}
static int *_getDepth(BiTree T, int *depth, int d)
{
if (NULL == T)
return depth;
*depth++ = d;
depth = getDepth(T->lchild, depth, d + 1);
depth = getDepth(T->rchild, depth, d + 1);
return depth;
}
Status getDepth(BiTree T, int **depth, int *count, int d)
{
int n = _getCount(T);
*depth = malloc(n * sizeof(int));
if (NULL == *depth)
return OVERFLOW;
*count = n;
_getDepth(T, *depth, d);
return OK;
}
Status getDepth(BiTree T, int **depth, int *count, int d) {
if(T == NULL)
return OK;
++d;
getDepth(T->lchild, depth, count, d);//还是这里问题,你if条件不
//成立,然后递归,然后在判断再递归,到if条件成立 退出函数?你这函数是这公呢能么?
if(T->lchild == NULL && T->rchild == NULL) {
depth[*count] = (int *)malloc(sizeof(int));
if (!depth[*count])
exit(OVERFLOW);
*(depth[*count]) = d;
(*count) ++;
}
getDepth(T->rchild, depth, count, d);
--d;
}