Commit c62ef9a4 authored by phelma's avatar phelma
Browse files

..

parent a3fef1fb
#include "graph.h"
list_t list_add_first(list_t l,arc_t arc){
list_t li=NULL;
li=calloc(1,sizeof(*li));
li->val=arc;
li->next=l;
return li;
}
void aff_sommet(vertex_t sommet){
list_t p;
printf(" Nom: %s\n",sommet.name);
printf(" Num: %d\n",sommet.num);
printf(" La Latitude: %lf ; La Longitude: %lf \n", sommet.a,sommet.b);
printf("Ligne: %s\n",sommet.ligne);
printf("les arcs associes:\n");
for(p=sommet.arcs;p!=NULL;p=p->next){
affiche_arc(p->val);
}
printf("\n");
printf("\n");}
graph_t lecture_graphe(FILE* f){
arc_t arc;
int numero;
double lat,longi;
graph_t g;
char mot[512];
fscanf(f,"%d %d",&g.size_vertex, &g.size_arcs);
int nbsommet=g.size_vertex;
int nbarc=g.size_arcs;
int i;
fgets(mot,511,f);
fgets(mot,511,f);
g.data=calloc(nbsommet,sizeof(vertex_t));
for(i=0;i<nbsommet;i++){
g.data[i].ligne=calloc(100,sizeof(char));
fscanf(f,"%d %lf %lf %s", &numero, &lat, &longi, g.data[i].ligne);
g.data[i].nom=calloc(100,sizeof(char));
fgets(g.data[i].nom,100,f);
g.data[i].numero=numero;
g.data[i].a=lat;
g.data[i].b=longi;}
fgets(mot,511,f);
for(i=0;i<nbarc;i++){
fscanf(f,"%d %d %lf",&arc.dep,&arc.end,&arc.cout);
fgets(mot,511,f);
g.data[arc.depart].arcs=list_add_first(g.data[arc.depart].arcs,arc);}
fclose(f);
return g;
}
void affiche_graphe(graph_t g){
int NBS=g.size_vertex;
int NBA=g.size_arcs;
printf("NBS: %d ; NBA: %d\n",NBS,NBA);
int i;
for(i=0;i<NBS;i++){
affiche_sommet(g.data[i]);}
}
void aff_arc(arc_t arc){
printf(" dep: %d ; Arr: %d ; cout: %lf \n",arc.dep,arc.end,arc.cout);
}
oid aff_sommet(vertex_t sommet){
list_t p;
printf(" Nom: %s\n",sommet.name);
printf(" Num: %d\n",sommet.num);
printf(" La Latitude: %lf ; La Longitude: %lf \n", sommet.a,sommet.b);
printf("Ligne: %s\n",sommet.ligne);
printf("les arcs associes:\n");
for(p=sommet.arcs;p!=NULL;p=p->next){
affiche_arc(p->val);
}
printf("\n");
printf("\n");}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment