Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Table 11-4.

Members of the BinaryTreeNode<T> class

Member Description
Overloaded constructor This constructor creates a BinaryTreeNode<T> object. Its syntax is:
BinaryTreeNode(T value)
where value is the object contained in this node, which will be used to compare to its
parent.
Left property A read-only property to retrieve the left child node below this node. Its syntax is:
BinaryTreeNode<T> Left {get;}
Right property A read-only property to retrieve the right child node below this node. Its syntax is:
BinaryTreeNode<T> Right {get;}
Children property Retrieves the number of child nodes below this node. Its syntax is:
Children( )
GetValue method Returns the IComparable<T> object that this node contains. Its syntax is:
GetValue( )
AddNode method Adds a new node recursively to either the left or right side. Its syntax is:
AddNode(BinaryTreeNode<T> node)
where node is the node to be added. Duplicate nodes may be added using this method.
AddUniqueNode method Adds a new node recursively to either the left side or the right side. Its syntax is:
AddUniqueNode(BinaryTreeNode<T> node)
where node is the node to be added. Duplicate nodes may not be added using this
method. A Boolean value is returned: true indicates a successful operation; false
indicates an attempt to add a duplicate node.
DepthFirstSearch method Searches for and returns a BinaryTreeNode<T> object in the tree, if one exists. This
method searches the depth of the tree first. Its syntax is:
DepthFirstSearch(T targetObj)
where targetObj is the object to be found in the tree.
PrintDepthFirst method Displays the tree in depth-first format. Its syntax is:
PrintDepthFirst( )
RemoveLeftNode method Removes the left node and any child nodes of this node. Its syntax is:
RemoveLeftNode( )
RemoveRightNode method Removes the right node and any child nodes of this node. Its syntax is:
RemoveRightNode( )

The code in Example 11-8 illustrates the use of the BinaryTree<T> and
BinaryTreeNode<T> classes when creating and using a binary tree.

Example 11-8. Using the BinaryTree and Binary TreeNode classes


public static void TestBinaryTree( )
{
BinaryTree<string> tree = new BinaryTree<string>("d");
tree.AddNode("a");
tree.AddNode("b");
tree.AddNode("f");
tree.AddNode("e");

Creating a Binary Search Tree | 425

You might also like