为什么一个对象被发送到这个函数中,但从未被使用

Why is an object sent into this function, but is never used?

本文关键字:一个对象 为什么 函数      更新时间:2023-10-16
int height(const Tree& T, const Position& p) {
    if (p.isExternal()) return 0;       // leaf has height 0
    int h = 0;
    PositionList ch = p.children();     // list of children
    for (Iterator q = ch.begin(); q != ch.end(); ++q)
      h = max(h, height(T, *q));
    return 1 + h;               // 1 + max height of children
  }

我的教科书给出了上面的代码来查找一般树的高度。为什么"树T"发送到函数,如果它从来没有使用(它的成员函数/变量从来没有调用或使用)在整个函数?

我想这是为了与其他函数保持某种一致性。例如,函数depth可能通过从树的根开始,并使用DFS找到该位置来计算位置的深度。

相关文章: