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
Constructors -
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.intnumChildren(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, sizeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.zybooks.dsaj.tree.BinaryTree
left, rightMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods 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:
siblingin 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:
numChildrenin interfaceTree<E>- Overrides:
numChildrenin 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:
childrenin 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
-