diff --git a/Msae.c b/Msae.c index e0b30b9..fa9e117 100644 --- a/Msae.c +++ b/Msae.c @@ -61,7 +61,7 @@ void afficherPlace(MaillonDept m) printf("\nPour ce département il y a %d places en 1ère année \n\n",m.nbP); } - +/* //################## fonctions insertion ######################### int insererDept(VilleIUT v, MaillonDept m) { @@ -101,4 +101,26 @@ MaillonDept* rechercheDept(ListeDept lDept, int *trouve, char nom[]) *trouve=0; return lDept; } +*/ + +int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve) +{ + int inf,sup,t; + inf=0; + sup=tLog-1; + while(inf<=sup) + { + t=(inf+sup)/2; + if(strcmp(ville,tiut[t]->nom)==0) + { + *trouve=1; + return t; + } + if(strcmp(ville,tiut[t]->nom)<0) + sup=t-1; + else inf=t+1; + } + *trouve=0; + return inf; +} diff --git a/Msae.h b/Msae.h index 206698b..1f46488 100644 --- a/Msae.h +++ b/Msae.h @@ -18,7 +18,7 @@ typedef struct maillonDept typedef struct { char nom[31]; - ListeDept *lDept; + ListeDept lDept; }VilleIUT; @@ -38,4 +38,5 @@ int insererDept(VilleIUT v, MaillonDept m); //######### fonction recherche ############## MaillonDept* rechercheDept(ListeDept lDept, int *trouve, char nom[ ] ); - +int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve); + diff --git a/Mtest.c b/Mtest.c index 42d6b55..e069b53 100644 --- a/Mtest.c +++ b/Mtest.c @@ -2,5 +2,22 @@ int main(void) { + VilleIUT* tiut[20]; + VilleIUT a,b,c,d; + char test[20]; + int trouve, pos; + strcpy(a.nom,"Clermont"); + strcpy(b.nom,"Lyon"); + strcpy(c.nom,"Paris"); + a.lDept = NULL; + b.lDept = NULL; + c.lDept = NULL; + tiut[0] = &a; + tiut[1] = &b; + tiut[2] = &c; + printf("Quel IUT cherchez-vous?\t"); + scanf("%s",test); + pos = rechercheIUT(tiut,4,test,&trouve); + printf("%d %d\n",pos,trouve); return 0; }