package t234; /** * Represents the abstract state of a 2-3-4 tree. * * @since 04/18/01 * @author Dung X. Nguyen, Copyright 2000 - All Rights Reserved. * @author Alan L. Cox */ abstract class ANode234 { /** * Checks the owner tree for emptiness. * * EXERCISE FOR STUDENTS: Remove this isEmpty method and rewrite the * insertion algorithm without checking for emptiness. */ abstract boolean isEmpty(Tree234 owner); /** * Inserts an Integer into the owner without duplication. * @param owner the owner of this ANode234. * @param n data object to be inserted. */ abstract void insert(Tree234 owner, Integer n); /** * Help insert an Integer into the owner, reconnecting the owner's * parent subtrees if needed. Called from insert. * * @param ownerPo the parent tree of the owner tree. * @param owner the owner of this ANode234. * @param n data object to be inserted. */ abstract void insertHelper(Tree234 ownerPo, Tree234 owner, Integer n); /** * Adds a data element with its left and right subtrees to this ANode234 * and reattaches it to the owner tree. * * @param owner * @param lTree a Tree234 whose elmements are less than n. * @param n the data element to be added. * @param rTree a Tree234 whose elements are greater than n. */ abstract void attach(Tree234 owner, Tree234 lTree, Integer n, Tree234 rTree); abstract void drawRootAndSubtrees(int level); final void drawAtLevel(int level) // invariant behavior { drawSpaces(level); drawRootAndSubtrees(level); } final void drawSpaces(int n) // invariant behavior { for (int i = 0; i < n; i++) System.out.print(" "); } }