/* * 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 version of the BTree contains Comparables instead of * simple characters. Note, however, that char is autoboxed to * Character, which implements Comparable. */ class Node3 { Comparable c; Node3 left, right; Node3(Comparable 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("%n"); pw.printf("%n",c); pw.printf("
%s
"); if(left != null) left.draw(pw); else pw.printf("∅"); pw.printf(""); if(right != null) right.draw(pw); else pw.printf("∅"); pw.printf("
%n"); } }