예제 #1
0
        public DigraphBase Square()
        {
            DigraphBase g = new AdjListDigraph(V);

            for (int i = 0; i < V; i++)
            {
                foreach (var j in Adj(i))
                {
                    g.AddEdge(i, j);
                    foreach (var k in Adj(j))
                    {
                        g.AddEdge(i, k);
                    }
                }
            }
            return(g);
        }
예제 #2
0
        public AdjListDigraph Square1()
        {
            AdjListDigraph g = new AdjListDigraph(V);

            for (int i = 0; i < V; i++)
            {
                Node cur = _nodes[i].Next;
                while (cur != null)
                {
                    g.AddEdge(i, cur.Val);
                    Node cur1 = _nodes[cur.Val];
                    while (cur1 != null)
                    {
                        g.AddEdge(i, cur1.Val);
                        cur1 = cur1.Next;
                    }
                    cur = cur.Next;
                }
            }
            return(g);
        }
예제 #3
0
        private static AdjListDigraph GetAdjListDigraph(int v, Tuple <int, int>[] edges)
        {
            AdjListDigraph g = new AdjListDigraph(v);

            foreach (var edge in edges)
            {
                g.AddEdge(edge.Item1, edge.Item2);
            }

            Console.WriteLine("Adjacency List Direct Graph: ");
            Console.WriteLine(g.ToString());
            return(g);
        }
예제 #4
0
        public DigraphBase Transpose()
        {
            DigraphBase g = new AdjListDigraph(V);

            for (int i = 0; i < V; i++)
            {
                ICollection <int> adj = Adj(i);
                foreach (var j in adj)
                {
                    g.AddEdge(j, i);
                }
            }
            return(g);
        }
예제 #5
0
        public AdjListDigraph Transpose1()
        {
            AdjListDigraph g = new AdjListDigraph(V);

            for (int i = 0; i < V; i++)
            {
                Node cur = _nodes[i].Next;
                while (cur != null)
                {
                    g.AddEdge(cur.Val, i);
                    cur = cur.Next;
                }
            }
            return(g);
        }
예제 #6
0
        public DigraphBase Deduplicate()
        {
            DigraphBase g = new AdjListDigraph(V);

            for (int i = 0; i < V; i++)
            {
                HashSet <int>     hashset = new HashSet <int>();
                ICollection <int> adj     = Adj(i);
                foreach (int j in adj)
                {
                    if (j != i && !hashset.Contains(j))
                    {
                        g.AddEdge(i, j);
                        hashset.Add(j);
                    }
                }
            }
            return(g);
        }
예제 #7
0
        public AdjListDigraph Deduplicate1()
        {
            AdjListDigraph g = new AdjListDigraph(V);

            for (int i = 0; i < V; i++)
            {
                HashSet <int> hashset = new HashSet <int>();
                Node          cur     = _nodes[i].Next;
                while (cur != null)
                {
                    if (cur.Val != i && !hashset.Contains(cur.Val))
                    {
                        g.AddEdge(i, cur.Val);
                        hashset.Add(cur.Val);
                    }
                    cur = cur.Next;
                }
            }
            return(g);
        }