
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Creating a Binary Tree
|
637
if (rightNode != null)
{
retObj = rightNode.DepthFirstSearch(targetObj);
}
}
else if (comparisonResult < 0)
{
if (leftNode != null)
{
retObj = leftNode.DepthFirstSearch(targetObj);
}
}
return (retObj);
}
public void PrintDepthFirst( )
{
if (leftNode != null)
{
leftNode.PrintDepthFirst( );
}
Console.WriteLine(this.nodeValue.ToString( ));
if (leftNode != null)
{
Console.WriteLine("\tContains Left: " +
leftNode.nodeValue.ToString( ));
}
else
{
Console.WriteLine("\tContains Left: NULL");
}
if (rightNode != null)
{
Console.WriteLine("\tContains Right: " +
rightNode.nodeValue.ToString( ));
}
else
{
Console.WriteLine("\tContains Right: NULL");
}
if (rightNode != null)
{
rightNode.PrintDepthFirst( );
}
}
public List<T> IterateDepthFirst( )
{
Example 11-11. Generic BinaryTreeNode class (continued)