Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal static List<T> BreadthFirstExpansion<T>(T root, Func<T,List<T>> getChildren) {
- List<T> list = new List<T>();
- list.Add(root);
- foreach(T entry in list) {
- List<T> children = getChildren(entry);
- if(children!=null) {
- foreach (T child in children)
- {
- if (!list.Contains(child)) list.Add(child);
- }
- }
- }
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement