我在树上通过递归找某一节点,
返回值为TreeNode,
当找到符合要求的节点后能立刻终止递归,返回得到的值么?
返回值为TreeNode,
当找到符合要求的节点后能立刻终止递归,返回得到的值么?
解决方案 »
- list泛型和类数组的问题
- DataGrid展现数据的语句问题。
- 怎样把一个泛型属值添加到一个xml文件上
- 目录下按文件名排序方法
- 如何遍历datagrid中一列可编辑文本框的值并将不为0的值写入数据库中?在线等!
- 请问:怎么激发DataGrid中行发生改变这一事件?
- 线程问题(急)
- oraclecommand已过时,如何修改?
- SQLServer 一条SQL语句 涉及两个数据库 C#如何实现
- 如何在C#中写如ASP中的Replace(string,VBCRLF,"<BR>")?
- 在C#中获取当前窗口的DC,等待高手指点ing...(1分是不多,但是我25%的积蓄)
- 在一个文件夹里写的文件个数过多时速度很慢的问题
{
if( tnParent == null ) return null;
if( tnParent.Text == strText ) return tnParent; TreeNode tnResult = null;
foreach( TreeNode tn in tnParent.Nodes )
{
tnResult = FindNode( tn, strText );
if( tnResult != null ) return tnResult;
}
return null;
}
解释的已经很好了
private TreeNode FindNode( TreeNode tnParent, string strValue )
{
if( tnParent == null ) return null; if( tnParent.Text == strValue ) return tnParent;
else if( tnParent.Nodes.Count == 0 ) return null; TreeNode tnCurrent, tnCurrentPar; tnCurrentPar = tnParent;
tnCurrent = tnCurrentPar.FirstNode; while( tnCurrent != null && tnCurrent != tnParent )
{
while( tnCurrent != null )
{
if( tnCurrent.Text == strValue ) return tnCurrent;
else if( tnCurrent.Nodes.Count > 0 )
{
tnCurrentPar = tnCurrent;
tnCurrent = tnCurrent.FirstNode;
}
else if( tnCurrent != tnCurrentPar.LastNode )
{
tnCurrent = tnCurrent.NextNode;
}
else
break;
}
while( tnCurrent != tnParent && tnCurrent == tnCurrentPar.LastNode )
{
tnCurrent = tnCurrentPar;
tnCurrentPar = tnCurrentPar.Parent;
} if( tnCurrent != tnParent )
tnCurrent = tnCurrent.NextNode;
}
return null;
}