天天看点

王道ch4-BiTree-8找出二叉树的双分支结点

//任务:找出二叉树的双分支结点
int dsonNode(BiTree& T)
{
	SqQueue Q; InitQueue(Q);
	BiTree p = T;
	EnQueue(Q, p);
	int i = 0;
	while (!IsEmpty(Q))
	{
		DeQueue(Q, p);
		if (p)
		{
			if (p->lchild && p->rchild)
				i++;
			if (p->lchild)
				EnQueue(Q,p->lchild);
			if (p->rchild)
				EnQueue(Q, p->rchild);
		}

	}
	return i;
}
           

继续阅读