コード例 #1
0
 public void AgregarVertice(cVertice vertice)
 {
     if ((vertice != null) && (!ExisteVertice(vertice)))
     {
         if (aVertice != null)
         {
             if (vertice.nombre.CompareTo(aVertice.nombre) < 0)
             {
                 cGrafo aux = new cGrafo(aVertice, aLista, aSiguiente);
                 aVertice   = new cVertice(vertice.nombre);
                 aSiguiente = aux;
             }
             else //Agregar
             {
                 aSiguiente.AgregarVertice(vertice);
             }
         }
         else
         {
             aVertice   = new cVertice(vertice.nombre);
             aLista     = new cLista();
             aSiguiente = new cGrafo();
         }
     }
 }
コード例 #2
0
 public cLista(cLista pLista)
 {
     if (pLista != null)
     {
         aElemento = pLista.aElemento;
         aSublista = pLista.aSublista;
         aPeso     = pLista.aPeso;
     }
 }
コード例 #3
0
 public void AgregarArco(cVertice pVerticeOrigen, cVertice pVerticeDestino, int pdistancia)
 {
     if (ExisteVertice(pVerticeOrigen) && (ExisteVertice(pVerticeDestino)))
     {
         AgregarArco(pVerticeOrigen, pVerticeDestino, pdistancia);
     }
     else
     {
         Console.WriteLine("ERROR. No se pudo agregar arco");
     }
 }
コード例 #4
0
 public bool ExisteElemento(cVertice pElemento)
 {
     if ((aElemento != null) && (pElemento != null))
     {
         return((aElemento.Equals(pElemento)) || (aSublista.ExisteElemento(pElemento)));
     }
     else
     {
         return(false);
     }
 }
コード例 #5
0
 public bool ExisteVertice(cVertice vertice)
 {
     if ((aVertice == null) || (vertice == null))
     {
         return(false);
     }
     else
     {
         return(aSiguiente.ExisteVertice(vertice));
     }
 }
コード例 #6
0
 public void Eliminar(cVertice pElemento)
 {
     if (pElemento != null)
     {
         if (aElemento.Equals(pElemento))
         {
             aElemento = aSublista.Elemento;
             aSublista = aSublista.Sublista;
         }
         else
         {
             aSublista.Eliminar(pElemento);
         }
     }
 }
コード例 #7
0
 private void agregarArco(cVertice pVerticeOrigen, cVertice pVerticeDestino, int pdistancia)
 {
     if (ExisteVertice(pVerticeOrigen))
     {
         if (aVertice.Equals(pVerticeOrigen))
         {
             //Agregar Arco
             if (!aLista.ExisteElemento(pVerticeDestino))
             {
                 aLista.Agregar(pVerticeDestino, pdistancia);
             }
         }
         else if (aSiguiente != null)
         {
             aSiguiente.agregarArco(pVerticeOrigen, pVerticeDestino, pdistancia);
         }
     }
 }
コード例 #8
0
 public int PosicionElemento(cVertice pElemento)
 {
     if ((aElemento != null) || (ExisteElemento(pElemento)))
     {
         if (aElemento.Equals(pElemento))
         {
             return(1);
         }
         else
         {
             return(1 + aSublista.PosicionElemento(pElemento));
         }
     }
     else
     {
         return(0);
     }
 }
コード例 #9
0
 public void Agregar(cVertice pElemento, int pPeso)
 {
     if (pElemento != null)
     {
         if (aElemento == null)
         {
             aElemento = new cVertice(pElemento.nombre);
             aPeso     = pPeso;
             aSublista = new cLista();
         }
         else
         {
             if (!ExisteElemento(pElemento))
             {
                 aSublista.Agregar(pElemento, pPeso);
             }
         }
     }
 }
コード例 #10
0
 public cLista(cVertice pElemento, cLista pSublista, int pPeso)
 {
     aElemento = pElemento;
     aSublista = pSublista;
     aPeso     = pPeso;
 }
コード例 #11
0
 //Constructores
 public cLista()
 {
     aElemento = null;
     aSublista = null;
     aPeso     = 0;
 }
コード例 #12
0
        static void Main(string[] args)
        {
            string   opcion;
            string   flag;
            cGrafo   Grafo = new cGrafo();
            cVertice ver   = new cVertice();
            cVertice ver1  = new cVertice();
            cVertice ver2  = new cVertice();

            do
            {
                Menu();
                opcion = Console.ReadLine();
                switch (opcion)
                {
                case "1":
                {
                    Console.WriteLine("¿Desea crear un nuevo grafo?: (S)/(N)");
                    flag = Console.ReadLine();
                    if (flag == "S")
                    {
                        Grafo = new cGrafo();
                        Console.WriteLine("Grafo Creado");
                    }
                    break;
                }

                case "2":
                {
                    Console.Write("Ingrese el nombre del vertice: ");
                    ver.nombre = Console.ReadLine();
                    Grafo.AgregarVertice(ver);
                    break;
                }

                case "3":
                {
                    Console.Write("Ingrese el vertice origen: ");
                    ver1.nombre = Console.ReadLine();
                    Console.WriteLine("Ingrese el vertice destino: ");
                    ver2.nombre = Console.ReadLine();
                    Console.WriteLine("Ingrese la distancia: ");
                    int dist = int.Parse(Console.ReadLine());
                    Grafo.AgregarArco(ver1, ver2, dist);
                    break;
                }

                case "4":
                {
                    Console.WriteLine("Los vertices del grafo son: ");
                    Grafo.MostrarVertices();
                    break;
                }

                case "5":
                {
                    Console.WriteLine("El grafo es el siguiente: ");
                    Grafo.MostrarGrafo();
                    break;
                }
                }
            }while (opcion != "0");
            Console.ReadKey();
        }
コード例 #13
0
 public cGrafo(cVertice pVertice, cLista pLista, cGrafo pSiguiente)
 {
     aVertice   = pVertice;
     aLista     = pLista;
     aSiguiente = pSiguiente;
 }
コード例 #14
0
 //Constructor
 public cGrafo()
 {
     aVertice   = null;
     aLista     = null;
     aSiguiente = null;
 }