Package com.zybooks.dsaj.tree
Interface Tree<E>
- Type Parameters:
E
- Element to be stored at each position of the tree.
- All Superinterfaces:
Iterable<E>
- All Known Subinterfaces:
BinaryTree<E>
- All Known Implementing Classes:
AbstractBinaryTree
,AbstractTree
,LinkedBinaryTree
,TreeMap.BalanceableBinaryTree
An interface for a tree where nodes can have an arbitrary number of children.
-
Method Summary
Modifier and TypeMethodDescriptionReturns an iterable collection of the Positions representing p's children.boolean
isEmpty()
Tests whether the tree is empty.boolean
isExternal
(Position<E> p) Returns true if Position p does not have any children.boolean
isInternal
(Position<E> p) Returns true if Position p has one or more children.boolean
Returns true if Position p represents the root of the tree.iterator()
Returns an iterator of the elements stored in the tree.int
numChildren
(Position<E> p) Returns the number of children of Position p.Returns the Position of p's parent (or null if p is root).Returns an iterable collection of the positions of the tree.root()
Returns the root Position of the tree (or null if tree is empty).int
size()
Returns the number of nodes in the tree.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
root
Returns the root Position of the tree (or null if tree is empty).- Returns:
- root Position of the tree (or null if tree is empty)
-
parent
Returns the Position of p's parent (or null if p is root).- Parameters:
p
- A valid Position within the tree- Returns:
- Position of p's parent (or null if p is root)
- Throws:
IllegalArgumentException
- if p is not a valid Position for this tree.
-
children
Returns an iterable collection of the Positions representing p's children.- Parameters:
p
- A valid Position within the tree- Returns:
- iterable collection of the Positions of p's children
- Throws:
IllegalArgumentException
- if p is not a valid Position for this tree.
-
numChildren
Returns the number of children of Position p.- Parameters:
p
- A valid Position within the tree- Returns:
- number of children of Position p
- Throws:
IllegalArgumentException
- if p is not a valid Position for this tree.
-
isInternal
Returns true if Position p has one or more children.- Parameters:
p
- A valid Position within the tree- Returns:
- true if p has at least one child, false otherwise
- Throws:
IllegalArgumentException
- if p is not a valid Position for this tree.
-
isExternal
Returns true if Position p does not have any children.- Parameters:
p
- A valid Position within the tree- Returns:
- true if p has zero children, false otherwise
- Throws:
IllegalArgumentException
- if p is not a valid Position for this tree.
-
isRoot
Returns true if Position p represents the root of the tree.- Parameters:
p
- A valid Position within the tree- Returns:
- true if p is the root of the tree, false otherwise
- Throws:
IllegalArgumentException
- if p is not a valid Position for this tree.
-
size
int size()Returns the number of nodes in the tree.- Returns:
- number of nodes in the tree
-
isEmpty
boolean isEmpty()Tests whether the tree is empty.- Returns:
- true if the tree is empty, false otherwise
-
iterator
Returns an iterator of the elements stored in the tree. -
positions
Returns an iterable collection of the positions of the tree.- Returns:
- iterable collection of the tree's positions
-