///// STUDENT TO FILL OUT ALL THE STUB METHODS IN THIS CLASS. package tree234; /** * Represents the empty state of a 2-3-4 tree. EmptyNode is an example of the Null object pattern. * Since there is conceptually only one empty state for all the 2-3-4 trees, * EmptyNode is implemented with the Singleton pattern. * @author Dung X. Nguyen - Copyright 2000 - All Rights Reserved. */ class EmptyNode extends ANode234 { final public static EmptyNode Singleton = new EmptyNode (); private EmptyNode () { } /** * Inserts an Integer into the owner tree without duplication. * This is the EmptyNode. So just asks the owner to change its state to a Node2. * @param n != null. * @param owner the owner of this EmptyNode. */ final void insert (Integer n, Tree234 owner) { //// STUDENT TO WRITE CODE. } /** * Helps the owner's parent tree insert data, using the other two owner's siblings if necessary. * This is the EmptyNode. So it is up to the other owner's siblings to decide what to do. * Hands one sibling to the other sibling and asks it to help owner's parent insert data. * @param ownerParent the parent of owner. * @param ownerSib1 one of the two siblings of owner. * @param ownerSib2 the sibling of sib1 and owner. * @param n an Integer to be properly inserted into ownerParent. * @param owner the owner of this EmptyNode */ void helpParentInsert(Tree234 ownerParent, Tree234 ownerSib1, Tree234 ownerSib2, Integer n, Tree234 owner) { //// STUDENT TO WRITE CODE. } /** * Helps the owner's parent insert data, using the one remaining owner's sibling if necessary. * This is the EmptyNode. So it is up to the given owner's remaining sibling to decide what to do. * Asks the owner's remaining sibling to help the owner's parent insert data. * @param ownerParent the parent of owner. * @param sib one of the two sibblings of owner. * @param n an Integer to be properly inserted into ownerParent. * @param owner the owner of this EmptyNode */ final void helpParentInsert(Tree234 ownerParent, Tree234 ownerSib, Integer n, Tree234 owner) { //// STUDENT TO WRITE CODE. } /** * Helps the owner's parent insert data with the knowledge that all the owner's siblings are empty. * This is the EmptyNode. Thus the owner's parent is a leaf. * Asks the owner's parent to insert data as a leaf. * @param ownerParent the parent of owner. * @param n an Integer to be properly inserted into ownerParent. * @param owner the owner of this EmptyNode */ final void helpParentInsert (Tree234 ownerParent, Integer n, Tree234 owner) { //// STUDENT TO WRITE CODE. } /** * Inserts data into owner when this EmptyNode is a leaf node. * Throws an IllegalStateException since the EmptyNode cannot be a leaf node. * @param n an Integer to be properly inserted into owner. * @param owner the owner of this EmptyNode */ final void insertAsLeaf(Integer n, Tree234 owner) { throw new IllegalStateException ("Empty tree cannot be a leaf!"); } /** * Inserts data into the owner when this EmptyNode is NOT a leaf node. * @param n an Integer to be properly inserted into owner. * @param owner the owner of this EmptyNode */ final void insertNotAsLeaf(Integer n, Tree234 owner) { //// STUDENT TO WRITE CODE. } /** * The owner of this EmptyNode is is a subtree of a given parent tree. * This is the EmptyNode, so there is no need to split the node. * Simply insert n into the owner tree. * @param ownerParent the parent of this tree. * @param n an Integer to be properly inserted into owner. * @param owner the owner of this EmptyNode */ final void insertAsChild (Tree234 ownerParent, Integer n, Tree234 owner) { insert (n, owner); // short cut for owner.insert (n); } /** * Attaches the 3 components a 2-node to the owner tree in the proper order. * Throws an IllegalStateException since the owner is an empty tree and * cannot be the parent of any tree. * @param lTree a 2-3-4 tree whose elements are less than n. * @param n a data element. * @param rTree a 2-3-4 tree whose elements are greater than n. * @param owner the owner of this EmptyNode, must be the parent of a Tree234. */ final void attach (Tree234 lTree, Integer n, Tree234 rTree, Tree234 owner ) { throw new IllegalStateException ("EmptyNode.attach (...) does not make sense!"); } }