Esempio n. 1
0
        private void FindCircuitDfs(Node currentNode)
        {
            if (Done)
            {
                return;
            }

            if (currentNode == StartNode && VisitedEdges.Count > 0)
            {
                Done = true;
                return;
            }
            List <Edge> adjEdges = Graph.GetEdges(currentNode);

            adjEdges = adjEdges.Where(e => VisitedEdges.All(ve => ve != e) && VisitedNodes.All(vn => vn != e.OtherNode(currentNode))).ToList();
            foreach (Edge adjEdge in adjEdges)
            {
                VisitedEdges.Add(adjEdge);
                Node otherNode = adjEdge.OtherNode(currentNode);
                VisitedNodes.Add(otherNode);
                FindCircuitDfs(otherNode);
                if (Done)
                {
                    return;
                }
                VisitedNodes.Remove(otherNode);
                VisitedEdges.Remove(adjEdge);
            }
        }