Package com.zybooks.dsaj.tree
Class AbstractBinaryTree<E>
java.lang.Object
com.zybooks.dsaj.tree.AbstractTree<E>
com.zybooks.dsaj.tree.AbstractBinaryTree<E>
- Type Parameters:
E
- Element to be stored at each position of the tree.
- All Implemented Interfaces:
BinaryTree<E>
,Tree<E>
,Iterable<E>
- Direct Known Subclasses:
LinkedBinaryTree
An abstract base class providing some functionality of the BinaryTree interface.
The following five methods remain abstract, and must be implemented
by a concrete subclass: size, root, parent, left, right.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns an iterable collection of the Positions representing p's children.inorder()
Returns an iterable collection of positions of the tree, reported in inorder.int
numChildren
(Position<E> p) Returns the number of children of Position p.Returns an iterable collection of the positions of the tree using inorder traversalReturns the Position of p's sibling (or null if no sibling exists).Methods inherited from class com.zybooks.dsaj.tree.AbstractTree
breadthfirst, depth, height, isEmpty, isExternal, isInternal, isRoot, iterator, postorder, preorder, size
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.zybooks.dsaj.tree.BinaryTree
left, right
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface com.zybooks.dsaj.tree.Tree
isEmpty, isExternal, isInternal, isRoot, iterator, parent, root, size
-
Constructor Details
-
AbstractBinaryTree
public AbstractBinaryTree()
-
-
Method Details
-
sibling
Returns the Position of p's sibling (or null if no sibling exists).- Specified by:
sibling
in interfaceBinaryTree<E>
- 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
-
numChildren
Returns the number of children of Position p.- Specified by:
numChildren
in interfaceTree<E>
- Overrides:
numChildren
in classAbstractTree<E>
- 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.
-
children
Returns an iterable collection of the Positions representing p's children.- Specified by:
children
in interfaceTree<E>
- 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.
-
inorder
Returns an iterable collection of positions of the tree, reported in inorder.- Returns:
- iterable collection of the tree's positions reported in inorder
-
positions
Returns an iterable collection of the positions of the tree using inorder traversal
-