82 lines
1.1 KiB
Java
82 lines
1.1 KiB
Java
/**
|
|
* A node of a binary tree.
|
|
*
|
|
* @author Marcus
|
|
*/
|
|
public class TreeNode {
|
|
|
|
/**
|
|
* The value of the node.
|
|
*/
|
|
private double value;
|
|
|
|
/**
|
|
* The left child, or null.
|
|
*/
|
|
private TreeNode left;
|
|
|
|
/**
|
|
* The right child, or null.
|
|
*/
|
|
private TreeNode right;
|
|
|
|
/**
|
|
* Creates a new tree node with
|
|
* the specified value and no
|
|
* children.
|
|
*
|
|
* @param value The value to set.
|
|
*/
|
|
public TreeNode(double value) {
|
|
this.value = value;
|
|
}
|
|
|
|
/**
|
|
* Returns the node value.
|
|
*
|
|
* @return The value of the node.
|
|
*/
|
|
public double getValue() {
|
|
return value;
|
|
}
|
|
|
|
/**
|
|
* Returns the left child or null.
|
|
*
|
|
* @return The left child or null.
|
|
*/
|
|
public TreeNode getLeft() {
|
|
return left;
|
|
}
|
|
|
|
/**
|
|
* Returns the right child or null.
|
|
*
|
|
* @return The right child or null.
|
|
*/
|
|
public TreeNode getRight() {
|
|
return right;
|
|
}
|
|
|
|
/**
|
|
* Sets the left child.
|
|
*
|
|
* @param left The new left child.
|
|
*/
|
|
public void setLeft(TreeNode left) {
|
|
this.left = left;
|
|
}
|
|
|
|
/**
|
|
* Sets the right child.
|
|
*
|
|
* @param right The new right child.
|
|
*/
|
|
public void setRight(TreeNode right) {
|
|
this.right = right;
|
|
}
|
|
|
|
|
|
|
|
}
|