btree->left=Create();
btree->right=Create();
return btree;
}
}
//求二叉树的高度,递归实现
int Height(BTree* bt)
{
int depth1,depth2;
if (NULL==bt)
{
return 0;
}
else
{
depth1=Height(bt->left);
depth2=Height(bt->right);
if (depth1>depth2)
{
return (depth1+1);
}
else
{
return (depth2+1);
}
}
}
int Width(BTree *T)//二叉树宽度
{
int static n[10];//向量存放各层结点数
int static i=1;
int static max=0;//最大宽度
if(T)
{
if(i==1) //若是访问根结点
{
n[i]++; //第1层加1
i++; //到第2层
if(T->left)//若有左孩子则该层加1
n[i]++;
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库数据结构_二叉树各种算法实现(2)在线全文阅读。
相关推荐: