public class Node { private Node left; //previous node private Node right; //next node int number; Node( int number, Node left, Node right){ this.setNumber(number); this.setLeft( left ); this.setRight( right ); } /** Accessors **/ /* Returns the value of number of the node */ public int getNumber(){ return this.number; } /* Returns the left node object * Note: null pointer possibility */ public Node getLeft(){ return this.left; } /* Returns the right node object * Note: null pointer possibility */ public Node getRight(){ return this.right; } /** Modifiers **/ /* Sets the value of the nodes number to * the value of the parameter number */ public void setNumber( int number ){ this.number = number; } /* Sets the reference to the node object left to * the parameter node object newLeftNode */ public void setLeft( Node newLeftNode ){ this.left = newLeftNode; } /* Sets the reference to the node object right to * the parameter node object newRightNode */ public void setRight( Node newRightNode ){ this.right = newRightNode; } /* Inserts a node between this node and the left node * with the value of the parameter number. * Returns a reference to the created node. */ public Node insertLeft( int number ){ Node newNode = new Node( number, this.getLeft(), this ); if( this.getLeft() != null ) this.getLeft().setRight( newNode ); this.setLeft( newNode ); return newNode; } /* Inserts a node between this node and the right node * with the value of the parameter number. * Returns a reference to the created node. */ public Node insertRight( int number ){ Node newNode = new Node( number, this, this.getRight() ); if( this.getRight() != null ) this.getRight().setLeft( newNode ); this.setRight( newNode ); return newNode; } /* Removes this node and seams together any left/right nodes * Returns the value of number; */ public int remove(){ if( this.getLeft() != null ) this.getLeft().setRight( this.getRight() ); if( this.getRight() != null ) this.getRight().setLeft( this.getLeft() ); return this.getNumber(); } }