I am creating an algorithm that is based on directed graphs. I would like a function that will grab all the nodes that are attached to a particular node.
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