public void AddEdge(string startName, string endName) { ProjectDfs start = GetOrCreateNode(startName); ProjectDfs end = GetOrCreateNode(endName); start.AddNeighbor(end); }
public void AddNeighbor(ProjectDfs node) { if (!map.ContainsKey(node.GetName())) { children.Add(node); map.Add(node.GetName(), node); node.IncrementDependencies(); } }
public ProjectDfs GetOrCreateNode(string name) { if (!map.ContainsKey(name)) { ProjectDfs node = new ProjectDfs(name); nodes.Add(node); map.Add(name, node); } return(map[name]); }
private static bool DoDfs(ProjectDfs project, Stack <ProjectDfs> stack) { if (project.GetState() == ProjectDfs.State.PARTIAL) { return(false); // cycle } if (project.GetState() == ProjectDfs.State.BLANK) { project.SetState(ProjectDfs.State.PARTIAL); List <ProjectDfs> children = project.GetChildren(); foreach (var child in children) { if (!DoDfs(child, stack)) { return(false); } } project.SetState(ProjectDfs.State.COMPLETE); stack.Push(project); } return(true); }