1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct {
int matrice_adjacence[50][50];
int temps[50][50];
} graphe;
graphe init_graphe(){
graphe G ; int i; int j;
for(i = 0 ; i <50 ; i ++){
for(j = 0 ; j <49 ; j++){
G.matrice_adjacence[i][j] = 0;
}
}
return G;
}
graphe alea_graphe(){
graphe G;
for(int i=0; i<50 ; i++){
int j =rand()%50;
G.matrice_adjacence[i][j]=1; G.matrice_adjacence[j][i]=1;
int a=rand()%30;
G.temps[i][j]=a; G.temps[j][i]=a;
}
return G;
}
void affiche_graphe(graphe G){
int i,j;
printf("Graphe avec %d sommets \n",50);
for(i = 0; i<50; i++){
printf("Voisins de %d: ",i);
for(j = 0; j < 50; j++){
if(G.matrice_adjacence[i][j]) printf("%d ",j);
}
printf("\n");
}
}
int main(){
graphe g;
g=init_graphe();
g=alea_graphe();
affiche_graphe(g);
} |
Partager