Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

Fields

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 gif 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.

   program18637
Program: BinarySearchTree class Key, Left and Right properties.


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.