예제 #1
0
        public GrafoDirigido(List <string> entradas)
        {
            foreach (string ent in entradas)
            {
                if (ent.Contains("#"))
                {
                    this.totalVerticesGrafo = int.Parse(ent.Substring(1, ent.Length - 1));
                }
                else
                {
                    string[] vetor = ent.Split(';');

                    Vertice vertice  = vetor[0].Equals("") ? null : new Vertice(vetor[0]);
                    Vertice vertice2 = vetor[1].Equals("") ? null : new Vertice(vetor[1]);
                    double  peso     = vetor[2].Equals("") ? 0 : double.Parse(vetor[2]);
                    //trataento em caso de nao definir valor
                    int    dir    = vetor[3].Equals("") ? 0 : int.Parse(vetor[3]);
                    Aresta aresta = null;
                    if (dir == -1)
                    {
                        aresta = new Aresta(vertice2, vertice, peso);
                    }
                    else if (dir == 1)
                    {
                        aresta = new Aresta(vertice, vertice2, peso);
                    }
                    this.vertices.Add(aresta);
                }
            }
        }
예제 #2
0
        public GrafoNaoDirigido(List <string> entradas)
        {
            foreach (string ent in entradas)
            {
                if (ent.Contains("#"))
                {
                    this.totalVerticesGrafo = int.Parse(ent.Substring(1, ent.Length - 1));
                }
                else
                {
                    string[] vetor = ent.Split(';');

                    Vertice vertice  = vetor[0].Equals("") ? null : new Vertice(vetor[0]);
                    Vertice vertice2 = vetor[1].Equals("") ? null : new Vertice(vetor[1]);
                    double  peso     = vetor[2].Equals("") ? 0 : double.Parse(vetor[2]);
                    Aresta  aresta   = new Aresta(vertice, vertice2, peso);
                    this.vertices.Add(aresta);
                }
            }
        }