/* BinaryTreeNode.java */ package dict; /** * BinaryTreeNode represents a node in a binary tree. * * DO NOT CHANGE THIS FILE. **/ class BinaryTreeNode { /** * key is the search key for the item stored in this node. * element is the element associated with this node's key. * leftChild and rightChild are the children of this node. **/ Comparable key; Object element; BinaryTreeNode parent; BinaryTreeNode leftChild, rightChild; /** Simple constructor that sets the key and the element. * The rest of the fields are set to null. */ BinaryTreeNode(Comparable key, Object element) { this(key, element, null, null, null); } /** Simple constructor that sets the key, element, and parent. * The rest of the fields are set to null. */ BinaryTreeNode(Comparable key, Object element, BinaryTreeNode parent) { this(key, element, parent, null, null); } /** Simple constructor that sets all of the node's fields. */ BinaryTreeNode(Comparable key, Object element, BinaryTreeNode parent, BinaryTreeNode left, BinaryTreeNode right) { this.element = element; this.key = key; this.parent = parent; leftChild = left; rightChild = right; } public String toString() { String s = ""; if (leftChild != null) { s = "(" + leftChild.toString() + ")"; } s = s + key.toString() + element; if (rightChild != null) { s = s + "(" + rightChild.toString() + ")"; } return s; } }