public static List<TreeNode> FindTreeNodes(TreeNode root, TreeNodeFindPredicate predicate) { List<TreeNode> result = new List<TreeNode>(); FindTreeNodesRecursive(root, predicate, result); return result; }
private static void FindTreeNodesRecursive(TreeNode n, TreeNodeFindPredicate predicate, List<TreeNode> arr) { if (predicate(n)) arr.Add(n); for (int i = 0; i < n.children.Count; i++) FindTreeNodesRecursive(n.children[i], predicate, arr); }