思路:實際上是在先序遍歷二叉樹。遞歸一次,說明深入了一層。所以,在每次進入遞歸之時該層節點數++。
int count[MaxSize];//全局數組
int max = -1;全局變量
void width(BitNode T, int k){
if(T==null)
return;
count[k]++;//該層節點數++
if(max<count[k])
max = count[k];
width(T->lchild,k+1);
width(T->rchild,k+1);
}
您可能感興趣的- 非遞歸先序遍歷二叉樹https://www.cnblogs.com/Coeus-P/p/9353186.html
- 非遞歸后序遍歷二叉樹版本二https://www.cnblogs.com/Coeus-P/p/9354754.html
- 遞歸算法--二叉樹寬度https://www.cnblogs.com/Coeus-P/p/9354671.html
- 遞歸算法--交換二叉樹左右子樹https://www.cnblogs.com/Coeus-P/p/9353568.html
- 遞歸算法--二叉樹高度https://www.cnblogs.com/Coeus-P/p/9353528.html
- 遞歸算法--二叉樹中葉子結點https://www.cnblogs.com/Coeus-P/p/9353505.html
- 遞歸算法--二叉樹中度為2的結點https://www.cnblogs.com/Coeus-P/p/9353495.html
- 遞歸算法--二叉樹中度為1的結點https://www.cnblogs.com/Coeus-P/p/9353484.html
- 非遞歸實現斐波那契數列https://www.cnblogs.com/Coeus-P/p/9353452.html
- 非遞歸后序遍歷二叉樹版本一https://www.cnblogs.com/Coeus-P/p/9353360.html
- 層次遍歷二叉樹https://www.cnblogs.com/Coeus-P/p/9353257.html
- 非遞歸中序遍歷二叉樹https://www.cnblogs.com/Coeus-P/p/9353227.html
- 非遞歸先序遍歷二叉樹https://www.cnblogs.com/Coeus-P/p/9353186.html