Exemple #1
0
  /**
   * Function to print the tree.
   *
   * @param depth Depth of the node in the tree.
   * @param text The tree.
   */
  private void printTree(int depth, StringBuffer text) {
    String aux = "";
    String aux2 = "";

    for (int k = 0; k < depth - 1; k++) {
      aux += "\t";
    }
    for (int k = 0; k < depth; k++) {
      aux2 += "\t";
    }

    text.append(aux2);
    if (nodo.isLeaf) {
      // text.append(nodo.printString() + " ["+indiceNodoT+"]\n");
      text.append(nodo.printString() + " \n");
    } else if (nodo != null) {
      /*text.append("[" + indiceNodo + "/" + marcado + "] if ( " +
      nodo.printString() +
      " ) then{\n");*/
      if (hijoI != null) {
        text.append("if ( " + nodo.printString() + " ) then{\n");
        hijoI.printTree(depth + 1, text);
      }
      if (hijoD != null) {
        text.append(aux2 + "else{ \n");
        hijoD.printTree(depth + 1, text);
      }
    }
    text.append(aux + "}\n");
  }