// Queue version -- only version totally working so far!
public boolean isMaximallyBalanced (TreeNode x){
boolean scanningNulls = false;
Deque q = new LinkedList ();
q.addFirst(x);
while (q.size() != 0) {
TreeNode n = q.remove();
if (scanningNulls) {
if (n != null)
return false;
}
else {
if (n == null) {
scanningNulls = true;
}
else {
q.add(n.myLeft);
q.add(n.myRight);
}
}
}
return true;
}
// Adopted from: www.boyet.com/Articles/CheckingForHeap.html
Monday, November 26, 2007
MaximallyBalanced or Complete Binary 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