static UFD searchfather(string fathername,UFD rootnode)
{//递归地寻找以home为根的name为fathername的节点
//如何打断for()递归
if (rootnode.name == fathername && rootnode.childUFD.Count < rootnode.childUFDcount)// && isGo==true)
{
return rootnode;
}
else
{
for (int i = 0; i < rootnode.childUFDcount; i++)
{
searchfather(fathername, (rootnode.childUFD[i]) as UFD);
}
}
return null;
}找到节点并返回后,程序还会继续执行。请问该怎么改或者其他什么好的算法。
{//递归地寻找以home为根的name为fathername的节点
//如何打断for()递归
if (rootnode.name == fathername && rootnode.childUFD.Count < rootnode.childUFDcount)// && isGo==true)
{
return rootnode;
}
else
{
for (int i = 0; i < rootnode.childUFDcount; i++)
{
searchfather(fathername, (rootnode.childUFD[i]) as UFD);
}
}
return null;
}找到节点并返回后,程序还会继续执行。请问该怎么改或者其他什么好的算法。
{
var ufd=searchfather(fathername, (rootnode.childUFD[i]) as UFD);
if(ufd != null)
{
return ufd;
}
}
static UFD searchfather(string fathername,UFD rootnode)
{//递归地寻找以home为根的name为fathername的节点
//如何打断for()递归
if(a==1)
{return null;//对空判断自行处理}
if (rootnode.name == fathername && rootnode.childUFD.Count < rootnode.childUFDcount)// && isGo==true)
{
a=1; return rootnode;
}
else
{
for (int i = 0; i < rootnode.childUFDcount; i++)
{
searchfather(fathername, (rootnode.childUFD[i]) as UFD);
}
}
return null;
}