Package dsa.iface

Interface ITree<T>

All Known Subinterfaces:
IBinaryTree<T>
All Known Implementing Classes:
AbstractBinaryTree

public interface ITree<T>
Interface representing a Tree data structure.
  • Method Details

    • root

      IPosition<T> root()
      Get the root position of the tree.
      Returns:
      The position object at the tree root.
    • parent

      IPosition<T> parent(IPosition<T> p)
      Get the parent of position p (or null if the position has no parent (i.e. is the root).
      Parameters:
      p -
      Returns:
      The IPosition representing the parent of p, or null if p is the root.
    • children

      Iterator<IPosition<T>> children(IPosition<T> p)
      Get an Iterator to iterate over the child positions of p.
      Parameters:
      p -
      Returns:
    • isInternal

      boolean isInternal(IPosition<T> p)
      Test whether position p is internal (i.e. has children).
      Parameters:
      p -
      Returns:
    • isExternal

      boolean isExternal(IPosition<T> p)
      Test whether position p is external (i.e. has no children).
      Parameters:
      p -
      Returns:
    • isRoot

      boolean isRoot(IPosition<T> p)
      Test whether position p is the root of the tree.
      Parameters:
      p -
      Returns:
      true if p is the root, false otherwise.
    • size

      int size()
      Get the size of the tree (i.e. the number of positions it contains).
      Returns:
    • isEmpty

      boolean isEmpty()
      Test whether the tree is empty.
      Returns:
      true if the size()==0, @{code false} otherwise.
    • iterator

      Iterator<T> iterator()
      Get an Iterator that iterates over all the elements contained in the tree's positions.
      Returns:
    • positions

      Iterator<IPosition<T>> positions()
      Get an Iterator that iterates over all the positions in the tree.
      Returns:
    • replace

      T replace(IPosition<T> p, T e)
      Replace the element contained in a position.
      Parameters:
      p - A position in the tree.
      e - The new element to store in p.
      Returns:
      The element that was formerly contained in the position before replacement.