how to write a non-recursive java function that computes the depth of a node in a tree(not binary) given that node
public int depth(Node node) {
int depth = 0;
while (node != root) {
node =node.parent;
depth++;
}
return depth;
}
this works for binary trees but what about if it is not binary