1 / 8

GRAFOS año: 2012

PRACTICO N° 6. GRAFOS año: 2012. 2. 3. 1. 6. 4. 5. Un grafo A consiste en un conjunto de vértices v y un conjunto de arcos a. Los vértices se denominan también puntos o nodos. G=(V,A) V={1,2,3,4,5,6}. Grafo dirigido.

myra-chaney
Télécharger la présentation

GRAFOS año: 2012

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PRACTICO N° 6 GRAFOSaño: 2012

  2. 2 3 1 6 4 5 Un grafo A consiste en un conjunto de vértices v y un conjunto de arcos a. Los vértices se denominan también puntos o nodos. G=(V,A) V={1,2,3,4,5,6} Grafo dirigido

  3. Grafo puede ser dirigido ( la relación entre los nodos se representa con una flecha) Grafo no dirigido(nodos no apuntados) Camino P de longitud n. es el n° de arcos que lo forman, desde el Vo al Vn. Grafo No dirigido: grado de entrada es el n° de arcos que contiene a v. Grafo dirigido: se distingue grado de entrada(n° de arcos que llegan a el nodo) y grado de salida(n° de arcos que salen de el) Adyacente: (u,v) el vertice u es adyacente a v y el vertice v es adyacente a u. Ciclo: en un grafo dirigido es un camino cerrado.

  4. // CLASE DEL GRAFO public class CGrafo { Vertice [] V; int [][]Matriz; int mv=5;// dimensión de la matriz Scanner ingreso; int numver=10;// número de nodos public CGrafo(){ // constructor Matriz=new int [mv][mv]; V=new Vertice[mv]; ingreso = new Scanner(System.in); } Implementación en jAVA

  5. public void GenerarMatriz(){ for(int i=0;i<mv;i++) for(int j=0;j<mv;j++) Matriz[i][j]=0; } public void GenerarVector(){ for(int i=0;i<V.length;i++){ System.out.println("Ingrese Vertice"); int elem = ingreso.nextInt(); System.out.println("Ingrese ciudad"); String ci = ingreso.next(); V[i]=new Vertice(elem,ci); } } generar la Matriz y el vector de nodos

  6. public void generarArco(){ Scanner entrada = new Scanner(System.in); char op = 's'; while (op != 'n') { System.out.println("Ingrese Vertice"); int elem = entrada.nextInt(); System.out.println("Ingrese Vertice 2"); int elem2 = entrada.nextInt(); AgregoArco(elem,elem2); System.out.println("Continuar s/n?"); op = entrada.next().charAt(0);} } // Agrego arco public void AgregoArco (int va, int vb){ if((va<0 || va>=mv) || (vb <0 || vb>=mv) ) System.out.println("no existe vertice"); else Matriz[vb][va]=1; } Generar el arco en la matriz

  7. publicvoid Mostrar(intmv){ for(int i=0;i<mv;i++){ System.out.println("\n "); for(int j=0;j<mv;j++){ System.out.print(Matriz[i][j]+" ");} } } Mostrar Matriz

  8. publicclassVertice { int numero; String ciudad; publicVertice(intn,Stringciu){ this.numero=n; this.ciudad=ciu;} // agregar los metodosget() y set() clase vertices(nodos)

More Related