Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
Program defines constructors for the BinaryTree class. The first one takes three arguments and assigns each of them to the corresponding field. Clearly the running time of this constructor is O(1).
Program: BinaryTree constructors, Left and Right properties
The second constructor, the no-arg constructor, creates an empty binary tree. It simply sets all three fields to null.
The third constructor takes as its argument any object. The purpose of this constructor is to create a binary tree with the specified object as its root. Since every binary tree has exactly two subtrees, this constructor creates two empty subtrees and assigns them to the left and right fields.
Program also defines the Left and Right properties. These properties provide get accessors that return the left and right subtrees of the given tree, respectively.