示例#1
0
        /// <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);
        }
示例#2
0
        /// <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);
        }
示例#3
0
 /// <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);
 }
示例#4
0
 /// <summary>
 /// Adds Vertice into Grafo.
 /// </summary>
 /// <param name="v"></param>
 public void AddVertice(Vertice v)
 {
     Vertices.Add(v);
     Adj.Update(this);
 }