Can I have a class, an abstract class moreover, that has two subclasses as objects?
I think that this one may need recursion as well as Nodes.
I almost wish I could have Node itself keep track of right and left subtrees.
public abstract class Node <T> { protected Node<T> left, right, parent; protected T data; protected ArrayList<T> childrenHolder; public Node(T data, Node<T> parent, Node<T> left, Node<T> right) { data = this.data; left = this.left; right = this.right; parent = this.parent; childrenHolder = new ArrayList<T>(); } public T getData() { return data; } public Node<T> getParent() { return parent; } public Node<T> getLeft() { return left; } public Node<T> getRight() { return right; } public abstract double evaluate(); public boolean isLeaf() { if (this.left == null && this.right == null) return true; else return false; } public int getImmediateChildren(Node<T> aNode) { if (aNode.isLeaf()) return 0; else if (((aNode.left == null && aNode.right != null) || (aNode.left != null && aNode.right == null))) return 1; else return 2; } public void setParent(Node<T> aParent) { this.parent = aParent; } public void setLeft(Node<T> newLeft) { this.left = newLeft; } public void setRight(Node<T> newRight) { this.right = newRight; } public boolean isRoot() { if (this.parent == null) return true; else return false; } public T getRoot(Node<T> aNode) { while (aNode.isRoot() == false) { aNode = aNode.getParent(); } return (aNode.getData()); } }