示例#1
0
        public GrafoDirigido_c(List <String> entrada)
        {
            foreach (string item in entrada)
            {
                if (item.Contains("#"))
                {
                    this.total_verticesGrafo = int.Parse(item.Substring(1, item.Length - 1));
                }
                else
                {
                    string[] vetString = item.Split(';');
                    Vertice  vertice1  = vetString[0].Equals("") ? null : new Vertice(vetString[0]);
                    Vertice  vertice2  = vetString[1].Equals("") ? null : new Vertice(vetString[1]);
                    int      peso      = vetString[2].Equals("") ? 0 : int.Parse(vetString[2]);
                    int      dir       = vetString[3].Equals("") ? 0 : int.Parse(vetString[3]);
                    Aresta   aresta    = null;
                    if (dir == -1)
                    {
                        aresta = new Aresta(vertice2, vertice1, peso);
                    }
                    else if (dir == 1)
                    {
                        aresta = new Aresta(vertice1, vertice2, peso);
                    }



                    this.vertices.Add(aresta);
                }
            }
        }
 public GrafoNDirigido(List <String> entradas)
 {
     foreach (string item in entradas)
     {
         if (item.Contains("#"))
         {
             this.total_verticesGrafo = int.Parse(item.Substring(1, item.Length - 1));
         }
         else
         {
             string[] vetor    = item.Split(';');
             Vertice  vertice  = vetor[0].Equals("") ? null : new Vertice(vetor[0]);
             Vertice  vertice2 = vetor[1].Equals("") ? null : new Vertice(vetor[1]);
             int      peso     = vetor[2].Equals("") ? 0 : int.Parse(vetor[2]);
             Aresta   aresta   = new Aresta(vertice, vertice2, peso);
             this.vertices.Add(aresta);
         }
     }
 }