Package edu.ksu.cis.viewer
Class BinaryTree
java.lang.Object
edu.ksu.cis.viewer.BinaryTree
- All Implemented Interfaces:
Serializable
,Cloneable
An immutable binary tree that can draw itself.
- Author:
- Rod Howell (rhowell@ksu.edu)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty BinaryTree.BinaryTree
(Node root, BinaryTree left, BinaryTree right) Constructs a BinaryTree with the given root and children. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Because this structure is immutable, this method simply returns this tree itself.Returns a drawing of this tree.getDrawing
(Font fnt) Returns a drawing of the tree using the given Font.Returns the left-hand child of this tree.Returns the right-hand child of this tree.getRoot()
Returns the root of this tree.boolean
isEmpty()
Returnstrue
if this tree is empty.
-
Constructor Details
-
BinaryTree
public BinaryTree()Constructs an empty BinaryTree. -
BinaryTree
Constructs a BinaryTree with the given root and children. If either BinaryTree parameter isnull
, an empty BinaryTree will be used for that child.- Parameters:
root
- the root of the treeleft
- the left childright
- the right child- Throws:
NullPointerException
- ifroot
isnull
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returnstrue
if this tree is empty.- Returns:
- whether this tree is empty
-
getRoot
Returns the root of this tree.- Returns:
- the root of this tree
- Throws:
EmptyTreeException
- If this tree is empty.
-
getLeftChild
Returns the left-hand child of this tree.- Returns:
- the left-hand child of this tree
- Throws:
EmptyTreeException
- If this tree is empty.
-
getRightChild
Returns the right-hand child of this tree.- Returns:
- The right child If this tree is empty.
- Throws:
EmptyTreeException
-
getDrawing
Returns a drawing of this tree.- Returns:
- a drawing of this tree
-
getDrawing
Returns a drawing of the tree using the given Font.- Parameters:
fnt
- the font to use- Returns:
- a drawing of this tree
- Throws:
NullPointerException
- iffnt
isnull
-
clone
Because this structure is immutable, this method simply returns this tree itself.
-