网站的360快照怎么做重庆网站外包
数据结构–树与二叉树–编程实现以孩子兄弟链表为存储结构递归求树的深度
题目:
编程实现以孩子兄弟链表为存储结构,递归求树的深度。
ps:题目来源2025王道数据结构
思路:
从根结点开始
结点 N 的高度 = `max{N 孩子树的高度 + 1, N兄弟树的高度}
代码:
#include <iostream>
#include <cmath>
using namespace std;
typedef struct CSNode{int data;struct CSNode *fcd, *fbod;
}CSNode, *CSTree;
int GetDeep(CSTree Tree)
{if (Tree == NULL) return 0;return max(GetDeep(Tree->fcd) + 1, GetDeep(Tree->fbod));
}
int main()
{CSTree Tree;//给 Tree 赋值操作 //... ... int deep = GetDeep(Tree);cout << deep;
}