示例#1
0
        public void AddEdge(string startName, string endName)
        {
            ProjectDfs start = GetOrCreateNode(startName);
            ProjectDfs end   = GetOrCreateNode(endName);

            start.AddNeighbor(end);
        }
示例#2
0
 public void AddNeighbor(ProjectDfs node)
 {
     if (!map.ContainsKey(node.GetName()))
     {
         children.Add(node);
         map.Add(node.GetName(), node);
         node.IncrementDependencies();
     }
 }
示例#3
0
        public ProjectDfs GetOrCreateNode(string name)
        {
            if (!map.ContainsKey(name))
            {
                ProjectDfs node = new ProjectDfs(name);
                nodes.Add(node);
                map.Add(name, node);
            }

            return(map[name]);
        }
示例#4
0
        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);
        }