Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
The BinarySearchTree class inherits the three fields key, left, and right from the BinaryTree class. The first refers to any object instance, and the latter two are BinaryTree instances which are the subtrees of the given tree. All three fields are null if the node represents the empty tree. Otherwise, the tree must have a root and two subtrees. Therefore, all three fields are non-null in an internal node.
Program defines the three properties Key, Left, and Right which access key, and the left and right subtrees, respectively, of a given binary search tree. In the BinaryTree class the left and right fields are BinaryTrees. However, in a binary search tree, the subtrees will be instances of the BinarySearchTree class. The Left and Right accessors cast the left and right fields to the appropriate type. Similarly, the Key accessor casts the key field to a ComparableObject.
Program: BinarySearchTree class Key, Left and Right properties.