user1824518
user1824518

Reputation: 223

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

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
  }

My textbook gives the above code for finding the height of a general tree. Why is "Tree T" sent into the function if it is never used (its member functions/variables never called or used) throughout the function?

Upvotes: 0

Views: 76

Answers (1)

anatolyg
anatolyg

Reputation: 28269

I guess it is for some sort of consistency with other functions. For example, a function depth might calculate the depth of a position by starting at the root of the tree and using DFS to find that position.

Upvotes: 1

Related Questions