//Increase the height only when the recursive call generates a new Iterator!!!
private static int height (T x) {
if (x.myChildren.isEmpty ( )) {
return 1;
} else {
int bestSoFar = 0;
Iterator iter = x.myChildren.iterator ( );
while (iter.hasNext ( )) {
T child = iter.next ( );
bestSoFar = Math.max (height(child) + 1, bestSoFar);
}
return bestSoFar;
}
}
Wednesday, November 21, 2007
Calculating the Height of a Tree
Subscribe to:
Post Comments (Atom)
Just some daily notes ...
Things I'm into now...
Blog Archive
-
▼
2007
(29)
-
▼
November
(14)
- Declaring an Edge Adjacency List Graph
- MaximallyBalanced or Complete Binary Tree
- Calculating the Height of a Tree
- Adding to a Circular Doubly Linked List
- 3 ways to REVERSE a list (singly linked)
- Reversing a List Iteratively!
- Doubling a Linked List
- Access Modifiers: public, private, proctecd, packa...
- End of HFJ
- Format Specifiers
- Collection class tidbits...
- Generic class definitions and one implementation
- doubling a List
- Don't Forget Your Scheme!
-
▼
November
(14)

No comments:
Post a Comment