struct node{
Node Left;
Node Right;
int MaxLeft;//左子树到该节点的最长距离
int MaxRight;//右子树到该节点的最长距离
char chValue;
};
void FindMaxLen(Node T)
{
int tmpMax = 0;
if (NULL == T)
{
return;
}
if (NULL == T->Left)
{
T->MaxLeft = 0;
}
if (NULL == T->Right)
{
T->MaxLeft = 0;
}
if (NULL != T->Left)
{
FindMaxLen(T->Left);
}
if (NULL != T->Right)
{
FindMaxLen(T->Right);
}
if (NULL != T->Left)
{
if (T->Left->MaxRight < T->Left->MaxLeft)
{
tmpMax = T->Left->MaxLeft + 1;
}
else
{
tmpMax = T->Left->MaxRight + 1;
}
T->MaxLeft = tmpMax;
}
if (NULL != T->Right)
{
tmpMax = 0;
if (T->Right->MaxRight < T->Right->MaxLeft)
{
tmpMax = T->Right->MaxLeft + 1;
}
else
{
tmpMax = T->Right->MaxRight + 1;
}
T->MaxRight = tmpMax;
}
if (T->MaxLeft + T->MaxRight > MaxLen)
{
MaxLen = T->MaxLeft + T->MaxRight;
}