You are on page 1of 2

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


Thanks to Wes for being a good uncle when I was busy.
Thanks to Tim Pelletier, Scott Cronshaw, Bill Bolevic, Melissa Field, Mike Kennie,
Jeremy Streeter, Bob & Liz Blais, Stu Savage, Matt Jurkoic, Dave Bennett, Rich
Tasker, Lance Simpson, Robert Provencal, and Shawn McGowan for being an awe-
some team of people to work with. 10X here we come.
Thanks to Kristen Acheson for being a great friend and part of the family.
Thanks to my Patriots crew (Brian, Spencer, Chip, Jon, and Darren) for being there
to help me blow off steam.
Thanks to the Oyster River Poker Players (Tom Bebbington, Seth Fiermonti, Gavin
Webb, John Clifford, Ben Chandran, Adam Gilsdorf, Nick Issak, and Ted Loth-
stein) for the nights off and for not taking too much of my money while my mind
was elsewhere. Pass the Sun Chips.
Finally, thanks again to my family and friends for asking about a book they don’t
understand and for being excited for me.

From Steve Teilhet


I’m proud to count Jay Hilyard as a good friend, excellent coworker, and hardwork-
ing coauthor. It’s not every day that you find a person who is not only a trusted
friend, but you also work so well with. Thank you for everything.
Kandis Teilhet, my wife, was there every step of the way to give me the strength to
persevere and finish this work. Words cannot express my love for you.
Patrick and Nicholas Teilhet, my two sons, made the rough patches smooth. I
couldn’t wish for two better sons.
My mom and dad, who are always there to listen and support.
The Ounce Lab team, Tom Conner, Larry Rose, David Larochelle, Caleb Davis, Rob-
ert Wiener, Ryan Berg, Cristian Bolovan, Dinis Cruz, Bruce Mayhew, and all the oth-
ers that made my transition from the closing of the NuMega Lab to the Ounce Lab
fun and exciting. It’s not easy changing jobs while writing a book. I thank you all for
the help and support.

xxvi | Preface

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

You might also like