GESP C++ 真题 · 逐题精解
首页C++六级真题 › 2024年9月 › 第10题

GESP 2024年9月 C++六级 单选题 第10题

C++六级单选题2024年9月第10题

所属知识点:深度优先搜索(DFS) 难度要求:— 考频:—

下面用 DFS(递归)计算二叉树深度,横线处应填入:
int max_depth(tree_node* root) {
    if (root == nullptr) return 0;
    int left_depth = max_depth(root->left);
    int right_depth = max_depth(root->right);
    ________ // 在此处填入代码
}

正确答案:C

题目解析

树的深度 = 左右子树较大深度 + 1(当前层),即 max(left_de………

完整解析为会员内容二级及以上的逐题精讲需开通 VIP。一级解析全部免费。前往 GESPPASS 解锁

想系统刷完 GESP C++ 1~8 级真题,并查看每道题的逐题精讲?

进入 GESPPASS 开始练习