Package com.zybooks.dsaj.tree
Interface BinaryTree<E>
- Type Parameters:
E
- Element to be stored at each position of the tree.
- All Known Implementing Classes:
AbstractBinaryTree
,LinkedBinaryTree
,TreeMap.BalanceableBinaryTree
An interface for a binary tree, in which each node has at most two children.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the Position of p's left child (or null if no child exists).Returns the Position of p's right child (or null if no child exists).Returns the Position of p's sibling (or null if no sibling exists).Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface com.zybooks.dsaj.tree.Tree
children, isEmpty, isExternal, isInternal, isRoot, iterator, numChildren, parent, positions, root, size
-
Method Details
-
left
Returns the Position of p's left child (or null if no child exists).- Parameters:
p
- A valid Position within the tree- Returns:
- the Position of the left child (or null if no child exists)
- Throws:
IllegalArgumentException
- if p is not a valid Position for this tree
-
right
Returns the Position of p's right child (or null if no child exists).- Parameters:
p
- A valid Position within the tree- Returns:
- the Position of the right child (or null if no child exists)
- Throws:
IllegalArgumentException
- if p is not a valid Position for this tree
-
sibling
Returns the Position of p's sibling (or null if no sibling exists).- Parameters:
p
- A valid Position within the tree- Returns:
- the Position of the sibling (or null if no sibling exists)
- Throws:
IllegalArgumentException
- if p is not a valid Position for this tree
-