
Untitled
By: a guest on
Apr 28th, 2012 | syntax:
None | size: 0.45 KB | hits: 25 | expires: Never
public double averageDepth() {
return (totalDepth(root, 0)/amountOfNodes(root));
}
public int totalDepth(Node<T> currentNode, int depth) {
if (currentNode == null){
return 0;
}
return depth + totalDepth(root.left, depth + 1) + totalDepth(root.right, depth + 1);
}
public int amountOfNodes(Node<T> currentNode) {
if (currentNode == null){
return 0;
}
return 1 + amountOfNodes(root.left) + amountOfNodes(root.right);
}