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

public abstract class AbstractBinaryTree<E> extends AbstractTree<E> implements BinaryTree<E>
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 Details

    • AbstractBinaryTree

      public AbstractBinaryTree()
  • Method Details

    • sibling

      public Position<E> sibling(Position<E> p)
      Returns the Position of p's sibling (or null if no sibling exists).
      Specified by:
      sibling in interface BinaryTree<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

      public int numChildren(Position<E> p)
      Returns the number of children of Position p.
      Specified by:
      numChildren in interface Tree<E>
      Overrides:
      numChildren in class AbstractTree<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

      public Iterable<Position<E>> children(Position<E> p)
      Returns an iterable collection of the Positions representing p's children.
      Specified by:
      children in interface Tree<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

      public Iterable<Position<E>> 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

      public Iterable<Position<E>> positions()
      Returns an iterable collection of the positions of the tree using inorder traversal
      Specified by:
      positions in interface Tree<E>
      Overrides:
      positions in class AbstractTree<E>
      Returns:
      iterable collection of the tree's positions using inorder traversal