/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package trees; import java.io.PrintWriter; /** * This is a different style of writing the recursive methods on the BTree. We * only put methods on the BTree class, not on the Node2. */ class Node2 { char c; Node2 left, right; Node2(char c) { this.c = c; } /** * Print out a textual representation of the tree. */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append('('); if (left == null) { sb.append('-'); } else { sb.append(left); } sb.append(' '); sb.append(c); sb.append(' '); if (right == null) { sb.append('-'); } else { sb.append(right); } sb.append(')'); return sb.toString(); } void draw(PrintWriter pw) { pw.printf("
%c | |
"); if (left != null) { left.draw(pw); } else { pw.printf("∅"); } pw.printf(" | "); if (right != null) { right.draw(pw); } else { pw.printf("∅"); } pw.printf(" |