diff --git a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj index 0774ec3..23bf212 100644 --- a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj +++ b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj @@ -87,6 +87,7 @@ + diff --git a/ICD.Common.Utils/RecursionUtils.cs b/ICD.Common.Utils/RecursionUtils.cs new file mode 100644 index 0000000..bef79d9 --- /dev/null +++ b/ICD.Common.Utils/RecursionUtils.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; + +namespace ICD.Common.Utils +{ + public static class RecursionUtils + { + /// + /// Returns all of the nodes in the tree via breadth-first search. + /// + /// + /// + /// + /// + public static IEnumerable BreadthFirstSearch(T root, Func> getChildren) + { + Queue process = new Queue(); + process.Enqueue(root); + + while (process.Count > 0) + { + T current = process.Dequeue(); + yield return current; + + foreach (T child in getChildren(current)) + process.Enqueue(child); + } + } + } +}