// Source: OpenDSA Data Structures and Algorithms Modules Collection: CHAPTER 12 BINARY TREES: https://opendsa-server.cs.vt.edu/ODSA/Books/Everything/html/BinaryTreeImpl.html

// Binary tree node implementation: supports comparable objects
class BSTNode<E extends Comparable<? super E>> implements BinNode<E> {
    private E element;           // Element for this node
    private BSTNode<E> left;     // Pointer to left child
    private BSTNode<E> right;    // Pointer to right child

    // Constructors
    BSTNode() {
        left = right = null;
    }
    BSTNode(E val) {
        left = right = null;
        element = val;
    }
    BSTNode(E val, BSTNode<E> l, BSTNode<E> r) {
        left = l;
        right = r;
        element = val;
    }

    // Get and set the element value
    public E value() {
        return element;
    }
    public void setValue(E v) {
        element = v;
    }

    // Get and set the left child
    public BSTNode<E> left() {
        return left;
    }
    public void setLeft(BSTNode<E> p) {
        left = p;
    }

    // Get and set the right child
    public BSTNode<E> right() {
        return right;
    }
    public void setRight(BSTNode<E> p) {
        right = p;
    }

    // return TRUE if a leaf node, FALSE otherwise
    public boolean isLeaf() {
        return (left == null) && (right == null);
    }
}