I have a class (Node) which has a property of SubNodes which is a List of the Node class
I have a list of Nodes (of which each Node may or may not have a list of SubNodes within itself) I need to be able to find a Node within the Node list/subNodes.
I have tried to do Find on the list but that will only search the Node classes within the list not the SubNodes list. Looked at the C5 library and a few binary trees but can t find anything suitable. any advice?
The class
public class Node
{
public Guid Id { get; set; }
public DateTime Created { get; set; }
public List<Node> Nodes { get;set;}
}
The function (result is the end result)
private void GetRecersive(List<Node> list, ref List<Node> result)
{
foreach (Node item in list)
{
if (item.ParentId.Equals(Guid.Empty))
{
result.Add(item);
}
else
{
result.ForEach(x => x.FindNodes(y => y.Id.Equals(item.ParentId)).FirstOrDefault().Nodes.Add(item));
}
List<Node> nodes = GetNodesByParent(item.Id);
GetRecersive(nodes, ref result);
}
}