试编写算法,对以孩子-兄弟链表表示的树计算深度。
孩子兄弟链表类型定义∶
typedef struct CSTNode {
TElemType data;
struct CSTNode *firstChild,*nextSibling;
} CSTNode,*CSTree;
要求实现下列函数∶
int TreeDepth(CSTree T);
/*求树T的深度*/
#include "allinclude.h" //DO NOT edit this line
int TreeDepth(CSTree T)
{ // Add your code here
if(T==NULL)return 0;
return ( TreeDepth(T->firstChild)+1) > TreeDepth(T->nextSibling) ? (TreeDepth(T->firstChild)+1) : TreeDepth(T->nextSibling) ;
}