0
我正在創建基於有向圖的算法。我想要一個將抓取所有連接到特定節點的節點的函數。將抓取連接到特定節點的所有節點的算法
public List<Node> GetNodesInRange(Graph graph, int Range, Node selected)
{
var result = new List<Node>();
result.Add(selected);
if (Range > 0)
{
foreach (Node neighbour in GetNeighbours(graph, selected))
{
result.AddRange(GetNodesInRange(graph, Range - 1, neighbour));
}
}
return result;
}
private List<Node> GetNeighbours(Graph graph, Node selected)
{
foreach(Node node in graph.node)
{
if (node == selected)
{
GetNodesInRange(node, Range-1, /*don't know what 2 do here*/);
//and confused all the way down
投票結束,因爲你的問題太模糊。 – spender 2010-04-19 01:49:36
到目前爲止您的解決方案是什麼? – 2010-04-19 02:32:45
上面編輯過,所以每個人都能理解 – GatesReign 2010-04-19 02:46:20