|
Mostrar Mensajes
|
Páginas: [1] 2
|
2
|
Programación / Programación General / Ayuda Con Este ERROR, GRAFOS
|
en: 25 Febrero 2020, 03:04 am
|
BUENO EXPLICO MI CASO, ESTOY INTENTANDO HACER UNA FUNCION QUE ME INSERTE UNA ARISTA PARA HACER UN BFS ,ESTA MI FUNCION Y CUANDO LO LLAMO EN EL MAIN CON DO WHILE, LO QUE SUCEDE ES QUE CUANDO QUIERO INSERTAR UNA ARISTA DE UN VERTICE A OTRO , ME SALE QUE EL PROGRAMA DEJO FUNCIONAR, ENTONCES NOSE SE TENGO ALGUN ERROR AL CODIFICAR O UN ERROR LOGICO, POR FAVOR UN ILUMINADO QUE ME AYUDE A RESOLVER ESTE DILEMA void Grafo::InsertarArista(Vertice *origen, Vertice *destino) { Arista *nueva = new Arista; nueva->sig=NULL; nueva ->ady=NULL; Arista *aux; aux = origen->ady; if(aux==NULL) { origen->ady = nueva; nueva->ady = destino; } else { while (aux !=NULL) { aux=aux->sig; } aux->sig = nueva; nueva->ady=destino; } }
case 2: { string origen, destino; system("cls"); if(G.vacio()) { cout<<"El grafo esta vacio"<<endl; } else { cout<<"Ingrese del nombre del vertice origen: "; cin.ignore(); getline(cin, origen, '\n'); cout<<"Ingrese el nombre del vertice destino: "; getline(cin, destino, '\n'); system("cls"); if(G.GetVertice(origen) == NULL || G.GetVertice(destino) == NULL) { cout<<"Uno de los vertices no es valido"<<endl; } else { G.InsertarArista(G.GetVertice(origen), G.GetVertice(destino));//, peso); } } cin.get(); cin.get(); break; }
|
|
|
4
|
Programación / Programación General / Re: Codigo para saber si este grafo es conexo
|
en: 19 Septiembre 2019, 18:58 pm
|
BUENO YA COMPILE Y TODO PERFECTO, PERO LA MATRIZ QUE LE INGRESE ES DE UN GRAFO CONEXO , ENTONCES NO ENTIENDO PORQUE SALIO EL FALSE, ME PERDI EN ESTA PARTE , que hize mal o pase por alto alguna cosa? package matriz_adyacencia; /** * * @author USUARIO */ public class Matriz_Adyacencia { /** * @param args the command line arguments */ public static void main (String[] args ) { Matriz_de_adyacencia matriz = new Matriz_de_adyacencia(5); Matriz_de_adyacencia Conexion = new Matriz_de_adyacencia(5); Conexion.esConexoo(); System. out. println(Conexion. esConexoo() ); matriz.agregar(0, 1); matriz.agregar(0, 1); matriz.agregar(0, 2); matriz.agregar(0, 3); matriz.agregar(1, 0); matriz.agregar(1, 0); matriz.agregar(1, 4); matriz.agregar(2, 0); matriz.agregar(2, 3); matriz.agregar(2, 4); matriz.agregar(3, 0); matriz.agregar(3, 2); matriz.agregar(4, 1); matriz.agregar(4, 2); matriz.agregar(4, 4); matriz.agregar(4, 4); matriz.imprimir(); } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package matriz_adyacencia; public class Matriz_de_adyacencia { public int n; public int[][] matriz; /** * Constructor de clase * @param n numero de nodos */ public Matriz_de_adyacencia(int n) { this.n = n; matriz = new int[this.n][this.n]; //se inicializa matriz en 0 for(int i=0; i< n; i++){ for(int j=0; j< n; j++){ matriz[i][j] = 0; } } } public void agregar(int i, int j){ matriz[i][j] += 1; } public void remover(int i, int j){ if(matriz[i][j]>0) matriz[i][j]-= 1; } public void imprimir(){ for(int i=0; i< n; i++){ for(int j=0; j< n; j++){ System. out. print( matriz [i ][j ] + " " ); } } } public boolean esConexoo(){ boolean conexoo=true; for(int i=0;i<matriz.length;i++){ for(int j=0;j<matriz.length;j++){ if(i!=j && matriz[i][j]==0){ conexoo = false; break; } } } return false; } }
|
|
|
5
|
Programación / Programación General / Re: Codigo para saber si este grafo es conexo
|
en: 19 Septiembre 2019, 17:24 pm
|
SUPONGO QUE ASI ESTARIA BUENO, AHORA SOLO FALTA LLAMAR LA FUNCION EN EL mAIN Y LISTO CREERIA YO, O FALTA alguna cosa? otra cosa que no tengo muy clara, SI RETORNA FALSE=NO CONEXO Y SI RETORNA TRUE=CONEXO? Y COMO PUEDO COMPROBARLO SI ME FUNCION, SUPONIENDO QUE TENGO TODO EL CODIGO HECHO public boolean esConexoo(){ boolean esConexoo=true; for(int i=0;i<matriz.length;i++){ for(int j=0;j<matriz.length;j++){ if(i!=j && matriz[i][j]==0){ esConexoo = false; break; } } } System. out. println(esConexoo ); return false; }
|
|
|
6
|
Programación / Programación General / Re: Codigo para saber si este grafo es conexo
|
en: 19 Septiembre 2019, 02:53 am
|
Entonces tendría que hacer otro ciclo que me vaya comparando los componentes de cada fila y de cada columna y que me diga si es cero o uno, y que los guarde en algun lado?
entonces tengo que crear otra funcion void recorrergrafo y que esa misma me diga si es conexo o no?
|
|
|
7
|
Programación / Programación General / Codigo para saber si este grafo es conexo
|
en: 18 Septiembre 2019, 18:41 pm
|
ESTE ES MI CODIGO LE INGRESO UNA MATRIZ DE NxN de un GRAFO NO DIRIGIDO, LO QUE NECESITO QUE ME AYUDEN ES COMO HAGO PARA RECORRER ESA MATRIZ Y DECIR SI EL GRAFO ES CONEXO O NO TEORIA GRAFO CONEXO un grafo es conexo si existe un camino de un nodo hacia cualquier otro nodo del grafo package matriz_adyacencia; /** * * @author PAPAYO */ public class Matriz_Adyacencia { /** * @param args the command line arguments */ public static void main (String[] args ) { Matriz_de_adyacencia matriz = new Matriz_de_adyacencia(5); matriz.agregar(0, 1); matriz.agregar(0, 1); matriz.agregar(0, 2); matriz.agregar(0, 3); matriz.agregar(1, 0); matriz.agregar(1, 0); matriz.agregar(1, 4); matriz.agregar(2, 0); matriz.agregar(2, 3); matriz.agregar(2, 4); matriz.agregar(3, 0); matriz.agregar(3, 2); matriz.agregar(4, 1); matriz.agregar(4, 2); matriz.agregar(4, 4); matriz.agregar(4, 4); matriz.imprimir(); } }
package matriz_adyacencia; public class Matriz_de_adyacencia { public int n; public int[][] matriz; /** * Constructor de clase * @param n numero de nodos */ public Matriz_de_adyacencia(int n) { this.n = n; matriz = new int[this.n][this.n]; //se inicializa matriz en 0 for(int i=0; i< n; i++){ for(int j=0; j< n; j++){ matriz[i][j] = 0; } } } public void agregar(int i, int j){ matriz[i][j] += 1; } public void remover(int i, int j){ if(matriz[i][j]>0) matriz[i][j] -= 1; } public void imprimir(){ for(int i=0; i< n; i++){ for(int j=0; j< n; j++){ System. out. print( matriz [i ][j ] + " " ); } } } }
ESPERO QUE ME AYUDEN GRACIASS
|
|
|
8
|
Programación / Programación C/C++ / Codigo Grafos C++
|
en: 5 Septiembre 2019, 20:49 pm
|
sabe alguno comO implementar o como programar esto,SON GRAFOS
1. (Si UN GRAFO es completamente conexo. 2. (Si tiene camino o circuito de Hamilton o ambos 3. (Si tiene camino o circuito de Euler o ambos 4. ( Ingresar los datos de dos vértices e indique cual es el camino más cortos entre ellos.
|
|
|
9
|
Programación / Programación General / Como se hace este autómata, alguien que me de una solucion
|
en: 28 Marzo 2019, 00:20 am
|
HE BUSCADO EN VARIAS PARTES Y NO HE PODIDO DAR CON UNA SOLUCION -> Construya el AFN que reconozca el lenguaje de todas las cadenas en base 3 que pueden iniciar en 00 o 22, deben contener 021 y terminar en 11, posteriormente conviertalo en un AFD. Dibuje los automatas y muestre la tabla de transicion de estados, as como el proceso de conversIon.-> Es posible construir un AFN con 3 estados que reconozca el lenguaje vacIo?
|
|
|
|
|
|
|