ondition: t != null, that is t is not an empty tree // postcondition: public static Object f(TreeNode t) { if (t.getLeft() == null && t.getRight() == null) { return t.getValue(); } else if (t.getLeft() == null) { return m(t.getValue(), f(t.getRight())); } else if (t.getRight() == null) { return m(t.getValue(), f(t.getLeft())); } else { return m(m(t.getValue(), f(t.getLeft())), f(t.getRight())); } } }
Note: this class has nothing to do with the standard Java interface javax.swing.tree.TreeNode
.
This implementation is provided at apcentral.
@version 1.0