zer*_*tor 0 c# algorithm recursion visual-studio
我写了一个递归函数.出于某种原因,它在第一次运行后才会自行调用.它只需要循环中的下一个项目而不会更深入.我正在使用Visual Studio 10,而且我睡不着觉.
public IEnumerable<string> GeneratePath(int depth)
{
int presentDepth = depth;
char currentPosition = this.workingPath[presentDepth];
presentDepth++;
foreach (char nextPosition in this.moveTable.GetPossibleNextPositions(currentPosition))
{
this.workingPath[presentDepth] = nextPosition;
if (presentDepth < (ChessPiece.targetDepth - 1))
{
Console.WriteLine("At least this wasn't ignored:{0}", new string(this.workingPath));
this.GeneratePath(presentDepth);
}
else
yield return new string(this.workingPath);
}
}
Run Code Online (Sandbox Code Playgroud)
this.GeneratePath(presentDepth);
Run Code Online (Sandbox Code Playgroud)
应该
foreach (var i in this.GeneratePath(presentDepth))
{
yield return ...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
107 次 |
| 最近记录: |