/// <summary> /// Returns the number of components from Graph /// </summary> /// <returns></returns> public int NumComponents() { bool[] marked = new bool[Vertices.Count]; Adj.Update(this); int count = 0; for (int i = 0; i < Vertices.Count; i++) { marked[i] = false; } for (int j = 0; j < Vertices.Count; j++) { if (!marked[j]) { DFS_search(j, marked, () => { }); count++; } } return(count); }
/// <summary> /// Adds Aresta into Grafo /// </summary> /// <param name="a"></param> /// <returns></returns> public bool AddAresta(Aresta a) { if (a.isDirected == isDigraph) { if (!Vertices.Contains(a.vertice1)) { Vertices.Add(a.vertice1); } if (!Vertices.Contains(a.vertice2)) { Vertices.Add(a.vertice2); } Arestas.Add(a); if (a.vertice1._id == a.vertice2._id) { isAciclic = false; // no longer aciclic } Adj.Update(this); } return(false); }
/// <summary> /// Overload, creates new Vertice from id and lbl. /// </summary> /// <param name="id"></param> /// <param name="lbl"></param> public void AddVertice(int id, string lbl) { Vertices.Add(new Vertice(lbl, id)); Adj.Update(this); }
/// <summary> /// Adds Vertice into Grafo. /// </summary> /// <param name="v"></param> public void AddVertice(Vertice v) { Vertices.Add(v); Adj.Update(this); }