Exemplo n.º 1
0
        public void BFS(Vertice <T> origen)
        {
            this.visitar(origen);             //Visito U
            Cola <Vertice <T> > cola = new Cola <Vertice <T> >();

            cola.encolar(origen);            //Encolo U
            while (!cola.esVacia())
            {
                Vertice <T> vertice = cola.desencolar();             //Desencolo U
                Console.Write(vertice.getDato() + " ");              //Muestro el dato de U
                if (vertice.getAdyacentes().Count != 0)              //Verifico que tenga vecinos
                {
                    List <Arista <T> > vecinos = vertice.getAdyacentes();
                    foreach (Arista <T> arista in vecinos)
                    {
                        if (!this.visitar(arista.getDestino()))
                        {
                            cola.encolar(arista.getDestino());                             //Encolos los vecinos de U que no fueron visitados
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void DFS(Vertice <T> origen)
        {
            if (!this.visitar(origen))                               //Verifico que U no este visitado
            {
                Console.Write(origen.getDato() + " ");               //Muestro el dato

                List <Arista <T> > vecinos = origen.getAdyacentes(); //Vecinos de U

                foreach (Arista <T> arista in vecinos)               //Verifico que U tenga vecinos
                {
                    this.DFS(arista.getDestino());                   //Recursivamente aplicamos DFS
                }
            }
        }
Exemplo n.º 3
0
        public void desConectar(Vertice <T> origen, Vertice <T> destino)
        {
            Arista <T> arista = origen.getAdyacentes().Find(a => a.getDestino().Equals(destino));

            origen.getAdyacentes().Remove(arista);
        }
Exemplo n.º 4
0
 public void conectar(Vertice <T> origen, Vertice <T> destino, int peso)
 {
     origen.getAdyacentes().Add(new Arista <T>(destino, peso));
 }