public void setAdyacencia(Adyacencia a) { La.Add(a); }
private void buttonAGREGARV_Click(object sender, EventArgs e) { if (textBoxCosto.Text == " " || textBoxDestino.Text == " " || textBoxOrigen.Text == " " || textBoxTiempo.Text == " " || textBoxOrigen.Text == "" || textBoxDestino.Text == "" || textBoxOrigen.Text == "a" || textBoxOrigen.Text == "b" || textBoxOrigen.Text == "c" || textBoxOrigen.Text == "d" || textBoxOrigen.Text == "e" || textBoxOrigen.Text == "f" || textBoxOrigen.Text == "g" || textBoxOrigen.Text == "h" || textBoxOrigen.Text == "i" || textBoxOrigen.Text == "j" || textBoxOrigen.Text == "k" || textBoxOrigen.Text == "l" || textBoxOrigen.Text == "m" || textBoxOrigen.Text == "n" || textBoxOrigen.Text == "o" || textBoxOrigen.Text == "p" || textBoxOrigen.Text == "q" || textBoxOrigen.Text == "r" || textBoxOrigen.Text == "s" || textBoxOrigen.Text == "t" || textBoxOrigen.Text == "u" || textBoxOrigen.Text == "v" || textBoxOrigen.Text == "w" || textBoxOrigen.Text == "x" || textBoxOrigen.Text == "y" || textBoxOrigen.Text == "z" || textBoxOrigen.Text == "ñ" || textBoxDestino.Text == "a" || textBoxDestino.Text == "b" || textBoxDestino.Text == "c" || textBoxDestino.Text == "d" || textBoxDestino.Text == "e" || textBoxDestino.Text == "f" || textBoxDestino.Text == "g" || textBoxDestino.Text == "h" || textBoxDestino.Text == "i" || textBoxDestino.Text == "j" || textBoxDestino.Text == "k" || textBoxDestino.Text == "l" || textBoxDestino.Text == "m" || textBoxDestino.Text == "n" || textBoxDestino.Text == "o" || textBoxDestino.Text == "p" || textBoxDestino.Text == "q" || textBoxDestino.Text == "r" || textBoxDestino.Text == "s" || textBoxDestino.Text == "t" || textBoxDestino.Text == "u" || textBoxDestino.Text == "v" || textBoxDestino.Text == "w" || textBoxDestino.Text == "x" || textBoxDestino.Text == "y" || textBoxDestino.Text == "z" || textBoxDestino.Text == "ñ" || textBoxCosto.Text == "" || textBoxTiempo.Text == "") { MessageBox.Show("ALGUN DATO ES INCORRECTO FAVOR DE INRODUCIRLO BIEN, DE LA A-Z EN MAYUSCULAS"); } else { if (!ValidarVueloNoRepetido()) { MessageBox.Show("EL VUELO YA EXISTE :("); return; } else { int banderaOrigen = 0; int banderaDestino = 0; //Grafo g=new Grafo(ref listavuelos); Vuelo v = new Vuelo(Convert.ToChar(textBoxOrigen.Text), Convert.ToChar(textBoxDestino.Text), Convert.ToInt32(textBoxTiempo.Text), Convert.ToInt32(textBoxCosto.Text)); //SI NO SE ENCUENTRAN LOS VUELOS if (g.CompararNodo(v.getOrigen())) { banderaOrigen = 1; } if (g.CompararNodo(v.getDestino())) { banderaDestino = 1; } if (banderaOrigen == 1) { Ciudad cD = new Ciudad(v.getOrigen()); Nodo nO = new Nodo(cD); // g.listaNodo.Add(nO); g.SetNodo(nO); } else { } if (banderaDestino == 1) { Ciudad cO = new Ciudad(v.getDestino()); Nodo nD = new Nodo(cO); // g.listaNodo.Add(nD); g.SetNodo(nD); } Nodo a = g.getNodoAdy(v.getOrigen()); Nodo b = g.getNodoAdy(v.getDestino()); Adyacencia Adyacente = new Adyacencia(b, v.costo, v.tiempo); a.setAdyacencia(Adyacente); listavuelos.Add(v); MessageBox.Show("VUELO AGREGADO CON EXITO!"); this.Close(); } } }
//int x, y; public Grafo(ref List <Vuelo> Lv) { this.listaNodo = new List <Nodo>(); this.listavuelo = Lv; foreach (Vuelo v in Lv) { bool banderaO = true; bool banderaD = true; foreach (Nodo n in listaNodo) { if (v.getOrigen() == n.getCiudad().nombreCiudad) { banderaO = false; } if (v.getDestino() == n.getCiudad().nombreCiudad) { banderaD = false; } } if (banderaO) { Ciudad c = new Ciudad(v.getOrigen()); Nodo n = new Nodo(c); listaNodo.Add(n); } if (banderaD) { Ciudad c = new Ciudad(v.getDestino()); Nodo n = new Nodo(c); listaNodo.Add(n); } } foreach (Nodo nod in listaNodo) { foreach (Vuelo V in Lv) { if (nod.getCiudad().nombreCiudad == V.getOrigen()) { foreach (Nodo Nod in listaNodo) { if (Nod.getCiudad().nombreCiudad == V.getDestino()) { Adyacencia AuxAdyacencia = new Adyacencia(Nod, V.costo, V.tiempo); nod.setAdyacencia(AuxAdyacencia); } } } } } foreach (Nodo n in listaNodo) { Console.WriteLine(n.getCiudad().nombreCiudad); foreach (Adyacencia _A in n.La) { Console.Write("-->" + _A.getNodoAd().getCiudad().nombreCiudad); } Console.WriteLine(); } }