/* This file is part of the algoviz@vt collection of algorithm visualizations. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this distribution. If not, see . */ /** * Represents one node of a Binary Search Tree that holds a key and value pair. * Based on Dr. Shaffer's C++ code. * * @author Andrew Whitaker (aawhitak@vt.edu) * */ public class BinNode implements BinNodeADT { /* This node's key */ private Key k; /* This node's element */ private Elem it; /* The node's left and right child */ BinNodeADT leftChild; BinNodeADT rightChild; /** * Creates a new node, and sets the left and right children to null. */ public BinNode() { leftChild = rightChild = null; } /** * Creates a new node with the specified parameters. * * @param key * The node's key * @param e * The node's value * @param l * The node's left child * @param r * The node's right child */ public BinNode(Key key, Elem e, BinNode l, BinNode r) { k = key; it = e; leftChild = l; rightChild = r; } /** * Convenience method to see if this node is a leaf. */ public boolean isLeaf() { return (leftChild == null) && (rightChild == null); } /** * Returns this node's left child. */ public BinNodeADT left() { return leftChild; } /** * Returns this node's right child. */ public BinNodeADT right() { return rightChild; } /** * Setter for this node's left child. */ public void setLeft(BinNodeADT l) { leftChild = l; } /** * Setter for this node's right child. */ public void setRight(BinNodeADT r) { rightChild = r; } /** * Sets the value of this node. */ public void setVal(Elem val) { it = val; } /** * Returns this elements value. */ public Elem val() { return it; } /** * @return This node's key */ public Key key() { return k; } }