/* * 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 uses a Comparator instead of * a Comparable Object. It is otherwise the same. */ class Node4 { Object c; Node4 left, right; Node4(Object 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("
%s | |
"); if(left != null) left.draw(pw); else pw.printf("∅"); pw.printf(" | "); if(right != null) right.draw(pw); else pw.printf("∅"); pw.printf(" |