private static void DFS(TreeNode node) { currentPath.Push(node.Value); if (node.Value == M) { if (allPaths.Count == 0 || currentPath.Count < allPaths[0].Count()) { allPaths.Add(currentPath.ToArray()); } } foreach (var child in node.Children) { DFS(child); } currentPath.Pop(); }
public Tree(int value) { this.root = new TreeNode(value); }
public void AddChild(TreeNode child) { this.children.Add(child); }