Esempio n. 1
0
int BTNodeHeight(BTNode *b)
{
    int lh,rh;
    if(b==null)return 0;
    else
    {
	lh=BTNodeHeight(b->l);
	rh=BTNodeHeight(b->r);
	return (lh>rh)?(lh+1):(rh+1);
    }
}
Esempio n. 2
0
int BTNodeHeight(BTNode *b) 
{
   	int lchildh,rchildh;
   	if (b==NULL) return(0); 				/*空树的高度为0*/
   	else  
	{
		lchildh=BTNodeHeight(b->lchild);	/*求左子树的高度为lchildh*/
		rchildh=BTNodeHeight(b->rchild);	/*求右子树的高度为rchildh*/
		return (lchildh>rchildh)? (lchildh+1):(rchildh+1);
   	}
}
Esempio n. 3
0
int
BTNodeHeight(BTNode *b)
{
	int lchildh, rchildh;
	if (!b)
		return 0;
	else {
		lchildh = BTNodeHeight(b->lchild);
		rchildh = BTNodeHeight(b->rchild);
		return (lchildh > rchildh) ? (lchildh + 1) : (rchildh + 1);
	}
}
Esempio n. 4
0
void DispBTree(BTNode *b)
{
    int n,i,j,high,
	level;
    PBTNode *p;
    PBTNode *pqu[MaxSize];
    PBTNode *levelpqu[MaxSize];
    n=CreatePBTNode(b,pqu);
    high=BTNodeHeight(b);
    j=0;
    level=1;
    pqu[0]->space=Pstart;
    for(i=0;i<=n;i++)
    {
	p=pqu[i];
	if(p->level==level)
	{
	    levelpqu[j]=p;
	    j++;
	}
	else
	{
	    PBTNodePrint(levelpqu,j,high);
	    level=p->level;
	    j=0;
	    levelpqu[j]=p;
	    j++;
	}
    }
    PBTNodePrint(levelpqu,j,high);

}
Esempio n. 5
0
int
main(int argc, char **argv)
{
	BTNode *bt;
	int height, width, nleaf, nnode;
	char exp[] = "A(B(D,E(H(J,K(L,M(,N))))),C(F,G(,I)))";

	bt = CreateBTNode(exp);
	DispBTNode(bt);
	puts("");
	nnode = CountBTNode(bt);
	nleaf = CountLeaf(bt);
	printf("%d %d\n", nnode, nleaf);
	FindNode(bt, 'H');
	height = BTNodeHeight(bt);
	width = CountWidth(bt);
	printf("%d %d\n", height, width-1);
	return 0;
}