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); }
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); }
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); }
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); }
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); }
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); }
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); }