Class TraversalExamples

java.lang.Object
com.zybooks.dsaj.tree.TraversalExamples

public class TraversalExamples extends Object
Several applications of tree traversals.
  • Constructor Details

    • TraversalExamples

      public TraversalExamples()
  • Method Details

    • spaces

      public static String spaces(int n)
      Returns a string containing n spaces.
    • printPreorder

      public static <E> void printPreorder(AbstractTree<E> T)
    • printPreorderIndentSlow

      public static <E> void printPreorderIndentSlow(AbstractTree<E> T)
    • printPreorderIndent

      public static <E> void printPreorderIndent(Tree<E> T, Position<E> p, int d)
      Prints preorder representation of subtree of T rooted at p having depth d.
    • printPreorderLabeled

      public static <E> void printPreorderLabeled(Tree<E> T, Position<E> p, ArrayList<Integer> path)
      Prints labeled representation of subtree of T rooted at p having depth d.
    • parenthesize

      public static <E> void parenthesize(Tree<E> T, Position<E> p)
      Prints parenthesized representation of subtree of T rooted at p.
    • diskSpace

      public static int diskSpace(Tree<Integer> T, Position<Integer> p)
      Returns total disk space for subtree of T rooted at p.
    • layout

      public static <E extends TraversalExamples.Geometric> int layout(BinaryTree<E> T, Position<E> p, int d, int x)
      Defines geometry for an inorder layout of subtree of a binary tree.