较好的思路是:用后序遍历的方式遍历整棵二叉树。在遍历某结点的左右子结点之后,我们可以根据它的左右子结点的深度判断它是不是平衡的,并得到当前结点的深度。当最后遍历到树的根结点的时候,也就判断了整棵一几叉树是不是平衡一叉树。这种方案每个结点只需遍历一次。
struct BinaryTreeNode{
	int m_nValue;
	BinaryTreeNode *m_pLeft;
	BinaryTreeNode *m_pRight;
};bool IsBalanced(BinaryTreeNode *pRoot, int *depth)
{
	if (pRoot==NULL)
	{
		*depth=0;
		return true;
	}
	//中间变量,记录左右子树的深度
	int left,right;
	if (IsBalanced(pRoot->m_pLeft,&left)&&IsBalanced(pRoot->m_pRight,&right))
	{
		//深度差
		int Dif=left-right;
		if (Dif<=1&&Dif>=-1)
		{
			*depth=1+(left>right?left:right);
			return true;
		}
	}
	return false;
}
//判断是否是平衡二叉树
bool IsBalanced(BinaryTreeNode *pRoot)
{
	int depth=0;
	return IsBalanced(pRoot,&depth);
}原文:http://blog.csdn.net/lsh_2013/article/details/46367987