示例#1
0
  public String toString() {
    int size = __getSize();
    int height = __getHeight();
    int widest = __getWidest() + 1;

    IntTreeNode.clearCycleData(20);
    String result = toString(overallRoot, 0, 0, size, height, widest);

    if (overallRoot == null) {
      result = "overallRoot\n   null";
    } else {
      String firstLine = "";
      int nodesLeft = __getSize(overallRoot.left);
      if (overallRoot.left != null && (overallRoot.cycle() || overallRoot.left.cycle())) {
        // nodesLeft = 0;
      }
      int spaces = (nodesLeft * widest) - Math.max(0, "overallRoot".length() - widest + 1) / 2;
      for (int i = 0; i < spaces; i++) {
        firstLine += " ";
      }
      firstLine += "overallRoot\n";

      int len = result.length();
      while (len < firstLine.length()) {
        result = " " + result;
        len += 2;
      }

      result = firstLine + result;
    }

    return result;
  }
示例#2
0
 public boolean equals(Object o) {
   IntTreeNode.clearCycleData();
   if (o instanceof IntTree) {
     IntTree other = (IntTree) o;
     return this.overallRoot == other.overallRoot || equals(this.overallRoot, other.overallRoot);
   } else {
     return false;
   }
 }
示例#3
0
 // post: prints the data fields of the tree using a preorder traversal
 public void printPreOrder() {
   IntTreeNode.clearCycleData();
   System.out.print("preorder:");
   printPreOrder(overallRoot);
   System.out.println();
 }
示例#4
0
 private int __getWidest() {
   IntTreeNode.clearCycleData();
   return __getWidest(overallRoot);
 }
示例#5
0
 private int __getSize() {
   IntTreeNode.clearCycleData();
   return __getSize(overallRoot);
 }
示例#6
0
 // post: prints the data fields of the tree, one per line, following
 //       an inorder traversal and using indentation to indicate node depth;
 //       prints right to left so that it looks correct when the output is
 //       rotated.
 public void printStructure() {
   IntTreeNode.clearCycleData();
   printStructure(overallRoot, 0);
 }