using System.Collections.Generic;
static void PrintNodes(List<SimpleNode> nodes)
foreach (var root in nodes)
Console.Write($"{root.Id} ");
public static void Main()
var tree = new SimpleTree
Nodes = new List<SimpleNode>
new SimpleNode { Id = "A" },
new SimpleNode { Id = "B" },
new SimpleNode { Id = "C" },
new SimpleNode { Id = "D" },
new SimpleNode { Id = "E" },
new SimpleNode { Id = "F" },
new SimpleNode { Id = "G" },
Relations = new List<SimpleNodeRelation>
new SimpleNodeRelation { ParentId = "A", ChildId = "E" },
new SimpleNodeRelation { ParentId = "B", ChildId = "E" },
new SimpleNodeRelation { ParentId = "C", ChildId = "F" },
new SimpleNodeRelation { ParentId = "E", ChildId = "F" },
new SimpleNodeRelation { ParentId = "D", ChildId = "G" },
public string Id { get; set; } = "";
public class SimpleNodeRelation
public string ChildId { get; set; } = "";
public string ParentId { get; set; } = "";
public List<SimpleNode> Nodes { get; set; } = new();
public List<SimpleNodeRelation> Relations { get; set; } = new();