Beispiel #1
0
 public void AddNode(int id)
 {
     if (!_table.ContainsKey(id))
     {
         _table[id] = new ProgramGraphNode(id);
     }
 }
 public void AddNeighbor(ProgramGraphNode neighbor)
 {
     if (!_neighbors.Contains(neighbor))
     {
         _neighbors.Add(neighbor);
         neighbor.AddNeighbor(this);
     }
 }
 public void VisitAllNodes(ProgramGraphNode cur, List <int> visited)
 {
     if (!visited.Contains(cur.Id))
     {
         visited.Add(cur.Id);
         foreach (var node in cur.Neighbors)
         {
             VisitAllNodes(node, visited);
         }
     }
 }
        private int CountGraph(ProgramGraphNode cur, List <int> visited)
        {
            var ret = 0;

            if (!visited.Contains(cur.Id))
            {
                ret = 1;
                visited.Add(cur.Id);
                foreach (var node in cur.Neighbors)
                {
                    ret += CountGraph(node, visited);
                }
            }
            return(ret);
        }
        private bool CanReach(int id, ProgramGraphNode cur, List <int> visited)
        {
            var ret = false;

            if (id == cur.Id)
            {
                return(true);
            }
            else if (!visited.Contains(cur.Id))
            {
                visited.Add(cur.Id);
                foreach (var node in cur.Neighbors)
                {
                    if (!ret)
                    {
                        ret = CanReach(id, node, visited);
                    }
                }
            }
            return(ret);
        }