Advertisement
eduardovp97

ex4Grafos.c

Dec 1st, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "Grafo.h"
  4.  
  5. void calcularGrados(TGrafo *grafo, TElemento elem);
  6.  
  7. int main(){
  8.  
  9.     TGrafo grafo;
  10.    
  11.     Grafo_init(&grafo);
  12.    
  13.     Grafo_insertarVertice(&grafo, 1);
  14.     Grafo_insertarVertice(&grafo, 2);
  15.     Grafo_insertarVertice(&grafo, 3);
  16.     Grafo_insertarVertice(&grafo, 4);
  17.     Grafo_insertarVertice(&grafo, 5);
  18. /*
  19.     Grafo_insertarVertice(&grafo, 6);
  20. */
  21.    
  22. /*
  23.     Grafo_insertarArista(&grafo, 1, 3);
  24.     Grafo_insertarArista(&grafo, 3, 5);
  25.     Grafo_insertarArista(&grafo, 5, 3);
  26.     Grafo_insertarArista(&grafo, 2, 3);
  27.     Grafo_insertarArista(&grafo, 2, 6);
  28.     Grafo_insertarArista(&grafo, 5, 6);
  29.     Grafo_insertarArista(&grafo, 4, 1);
  30.     Grafo_insertarArista(&grafo, 4, 5);
  31. */
  32.    
  33.     Grafo_insertarArista(&grafo, 1, 2, 3.0);
  34.     Grafo_insertarArista(&grafo, 2, 1, 3.0);
  35.    
  36.     Grafo_insertarArista(&grafo, 1, 4, 7.0);
  37.     Grafo_insertarArista(&grafo, 4, 1, 7.0);
  38.    
  39.     Grafo_insertarArista(&grafo, 2, 3, 4.0);
  40.     Grafo_insertarArista(&grafo, 3, 2, 4.0);
  41.    
  42.     Grafo_insertarArista(&grafo, 2, 4, 2.0);
  43.     Grafo_insertarArista(&grafo, 4, 2, 2.0);
  44.    
  45.     Grafo_insertarArista(&grafo, 3, 4, 5.0);
  46.     Grafo_insertarArista(&grafo, 4, 3, 5.0);
  47.    
  48.     Grafo_insertarArista(&grafo, 3, 5, 6.0);
  49.     Grafo_insertarArista(&grafo, 5, 3, 6.0);
  50.    
  51.     Grafo_insertarArista(&grafo, 4, 5, 4.0);
  52.     Grafo_insertarArista(&grafo, 5, 4, 4.0);
  53.    
  54.     Grafo_imprimirGrafo(&grafo);
  55.    
  56.     //Grafo_imprimirCaminosMasCortos(&grafo, 1);
  57.     printf("\n");
  58.     calcularGrados(&grafo,1);
  59.     calcularGrados(&grafo,2);
  60.     calcularGrados(&grafo,3);
  61.     calcularGrados(&grafo,4);
  62.     calcularGrados(&grafo,5);
  63.  
  64.     return 0;
  65. }  
  66.  
  67. void calcularGrados(TGrafo *grafo, TElemento elem){
  68.     TVertice *ptr = grafo->inicio;
  69.     int entrada = 0, salida = 0;
  70.     while(ptr){
  71.         if(ptr->info == elem)
  72.             salida = ptr->lstAdyacentes.numElem;
  73.         if(Lista_EstaEnLista(ptr->lstAdyacentes, elem)){
  74.             entrada++;
  75.         }
  76.         ptr = ptr -> sig;
  77.     }
  78.     printf("Grados de entrada : %d\nGrados de salida: %d\n",entrada,salida);
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement