private static void CullVisitedNodes <T>(RootFinder finder, List <T> adjacent) where T : GraphElement <T> { foreach (var node in finder.Visited) { node.RemoveFromGraph(); } }
private static void RemoveVisitedNodes <T>(RootFinder finder, List <T> adjacent) where T : GraphElement <T> { for (var index = adjacent.Count - 1; index >= 0; index--) { if (finder.Contains(adjacent[index])) { adjacent.RemoveAt(index); } } }
public static void RemoveNodes <T>(List <T> nodes) where T : GraphElement <T> { var adjacent = GetAdjacentNodes(nodes); foreach (var node in nodes) { node.DisconnectAll(); } var finder = new RootFinder(); while (adjacent.Count > 0) { finder.Reset(); var connected = finder.IsConnectedToRoot(adjacent[0]); RemoveVisitedNodes(finder, adjacent); if (!connected) { CullVisitedNodes(finder, adjacent); } } }