ajout rechercheDept(compile pas) et insererDept(a besoin de rechercheDept) + rechercheIUT finie/testée

master
Maël DAIM 2 years ago
parent d37f972a8e
commit 54026f1469

@ -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); printf("\nPour ce département il y a %d places en 1ère année \n\n",m.nbP);
} }
/*
//################## fonctions insertion ######################### //################## fonctions insertion #########################
int insererDept(VilleIUT v, MaillonDept m) int insererDept(VilleIUT v, MaillonDept m)
{ {
@ -101,4 +101,26 @@ MaillonDept* rechercheDept(ListeDept lDept, int *trouve, char nom[])
*trouve=0; *trouve=0;
return lDept; 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;
}

@ -18,7 +18,7 @@ typedef struct maillonDept
typedef struct typedef struct
{ {
char nom[31]; char nom[31];
ListeDept *lDept; ListeDept lDept;
}VilleIUT; }VilleIUT;
@ -38,4 +38,5 @@ int insererDept(VilleIUT v, MaillonDept m);
//######### fonction recherche ############## //######### fonction recherche ##############
MaillonDept* rechercheDept(ListeDept lDept, int *trouve, char nom[ ] ); MaillonDept* rechercheDept(ListeDept lDept, int *trouve, char nom[ ] );
int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve);

@ -2,5 +2,22 @@
int main(void) 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; return 0;
} }

Loading…
Cancel
Save