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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| #include <stdio.h>
#define Max 100
/********************************************************************************/
/* DECLARATIONS DES TYPES */
/********************************************************************************/
typedef int couleur[Max];
typedef struct sommet
{
int numero;
int degre;
couleur couleursommet;
}sommet;
typedef struct arc
{
sommet sommetdedepart;
sommet sommetdarrivee;
}arc;
/********************************************************************************/
/* PROCEDURES ET FONCTIONS CORRECTES */
/********************************************************************************/
void calculdegre(sommet *sommet1, arc listearc[],int nbarc)
{
int i=0;
int compteur=0;
for (i=0;i<=nbarc-1;i++)
{
if((listearc[i].sommetdedepart.numero==(*sommet1).numero)||(listearc[i].sommetdarrivee.numero==(*sommet1).numero))
{
compteur=compteur+1;
}
}
(*sommet1).degre=compteur;
}
/********************************************************************************/
/* PROCEDURE EN COUR DE CREATION */
/********************************************************************************/
void calculertouslesdegres(arc listearc[],sommet listesommet[],int nbsommet,int nbarc)
{
int i;
for(i=0;i<=nbsommet-1;i++)
{
calculdegre(&listesommet[i],listearc,nbarc);
}
}
/********************************************************************************/
/* PROGRAMME PRINCIPAL */
/********************************************************************************/
void main (void)
{
sommet listesommet[Max],listesommetretour[Max];
arc listearc[5*Max];
sommet a;
int nbsommet=2;
int nbarc=3;
a.numero=1;
listesommet[0]=a;
listearc[0].sommetdedepart=a;
listearc[1].sommetdedepart=a;
listearc[2].sommetdedepart=a;
calculertouslesdegres(listearc,&listesommet,nbsommet,nbarc);
printf("\n%d\n",a.degre);
} |
Partager