Esempio n. 1
0
        public bool DetectCycle(Graph graph)
        {
            //Detect Cycle
            for (int i = 0; i < graph.GraphEdges; i++)
            {
                int src = graph.Edges[i].Source;
                int des = graph.Edges[i].Destination;

                int xLeader = graph.FindPathByCompression(graph.DisJointSets, src);
                int yleader = graph.FindPathByCompression(graph.DisJointSets, des);

                if (xLeader == yleader)
                {
                    return true;
                }
                graph.UnionByRank(xLeader, yleader);

            }
            return false;
        }