Skip to content
Snippets Groups Projects
Commit a466d287 authored by Abdul-Malik Elmurzaev's avatar Abdul-Malik Elmurzaev
Browse files

correction bugs car ils empechaient chemin2 de fonctionner. Toutes les...

correction bugs car ils empechaient chemin2 de fonctionner. Toutes les fonctions dont chemin2 sont vérifiés, aucune memory leak
parent 847123e1
Branches
1 merge request!5fonctions jusqu'à chemin2 incluse sont vérifiées. Aucune memory leak
...@@ -292,8 +292,10 @@ int compArc(void *a, void *string){ ...@@ -292,8 +292,10 @@ int compArc(void *a, void *string){
void adjEntite(Relations g, char *nom, etype t){ void adjEntite(Relations g, char *nom, etype t){
listeg copy = g->listDeRelations; listeg copy = g->listDeRelations;
while(copy != NULL){ while(copy != NULL){
if( ((Sommet)(copy->val))->x->nom == nom ) if( ((Sommet)(copy->val))->x->nom == nom ){
printf("check \n");
return; return;
}
copy = copy->suiv; copy = copy->suiv;
} }
g->listDeRelations = adjqueue(g->listDeRelations, nouvSommet(creerEntite(nom, t))); g->listDeRelations = adjqueue(g->listDeRelations, nouvSommet(creerEntite(nom, t)));
...@@ -333,11 +335,12 @@ void adjRelation(Relations g, char *nom1, char *nom2, rtype id){ ...@@ -333,11 +335,12 @@ void adjRelation(Relations g, char *nom1, char *nom2, rtype id){
// 4.1 listes de relations // 4.1 listes de relations
listeg en_relation(Relations g, char *x){ listeg en_relation(Relations g, char *x){
listeg res = listegnouv(); listeg res = listegnouv();
while(g->listDeRelations != NULL){ listeg copyTete = g->listDeRelations;
if( strcmp( ((Sommet)(g->listDeRelations->val))->x->nom, x ) == 0 ){ while(copyTete != NULL){
return ((Sommet)(g->listDeRelations->val))->larcs; if( strcmp( ((Sommet)(copyTete->val))->x->nom, x ) == 0 ){
return ((Sommet)(copyTete->val))->larcs;
} }
g->listDeRelations = g->listDeRelations->suiv; copyTete = copyTete->suiv;
} }
return res; return res;
} }
...@@ -364,18 +367,20 @@ listeg chemin2(Relations g, char *x, char *y){ // on renvoit une LISTE D ENTITE ...@@ -364,18 +367,20 @@ listeg chemin2(Relations g, char *x, char *y){ // on renvoit une LISTE D ENTITE
listeg YEntites_copy = YEntites; listeg YEntites_copy = YEntites;
while(XEntites_copy != NULL){ while(XEntites_copy != NULL){
YEntites_copy = YEntites;
while(YEntites_copy != NULL){ while(YEntites_copy != NULL){
//printf("a \n"); //printf("a \n");
if( compEntite(XEntites_copy->val, ((Entite)(YEntites_copy->val))->nom) ){ if( compEntite(XEntites_copy->val, ((Entite)(YEntites_copy->val))->nom) ){
RES = adjqueue(RES, XEntites_copy->val); RES = adjqueue(RES, XEntites_copy->val );
printf("check \n");
//printf(" ___________ %s \n", ((Entite)(RES->val))->nom ); //printf(" ___________ %s \n", ((Entite)(RES->val))->nom );
} }
YEntites_copy = YEntites_copy->suiv; YEntites_copy = YEntites_copy->suiv;
} }
XEntites_copy = XEntites_copy->suiv; XEntites_copy = XEntites_copy->suiv;
} }
free(XEntites); detruire(XEntites);
free(YEntites); detruire(YEntites);
return RES; return RES;
} }
// 4.2 verifier un lien de parente // 4.2 verifier un lien de parente
...@@ -432,34 +437,6 @@ void affiche_degre_relations(Relations r, char *x){ ...@@ -432,34 +437,6 @@ void affiche_degre_relations(Relations r, char *x){
int main(){ int main(){
int i,j; int i,j;
printf("test toStringRelation(16) == %s \n", toStringRelation(16));
printf("test est_lien_parente : %d %d %d \n",est_lien_parente(COUSIN),est_lien_parente(LOCATAIRE),
est_lien_parente(EPOUX));
printf("test est_lien_professionel : %d %d %d \n", est_lien_professionel(LOCATAIRE),
est_lien_professionel(CHEF), est_lien_professionel(COLLEGUE));
printf("test est_lien_connaissance : %d %d %d \n", est_lien_connaissance(AMI),
est_lien_connaissance(CONNAIT), est_lien_connaissance(COLLEGUE));
listeg liste = listegnouv();
int x5 = 5, x4 = 4, x19 = 19, x3 = 3, x33 = 33;
int *px5, *px4, *px19, *px3, *px33;
px5 = &x5; px4 = &x4; px19 = &x19; px3 = &x3; px33 = &x33;
int x0 = 0; int* px0 = &x0;
liste = adjqueue(liste, &px5);
liste = adjtete(liste, &px4);
liste = adjqueue(liste, &px19);
liste = adjtete(liste, &px3);
liste = adjqueue(liste, &px33);
liste = adjtete(liste, &px0);
liste = suptete(liste);
listeg copy = liste;
for(int i=0; i<4; i++){
printf("liste->val == %d \n", **(int**)copy->val);
copy = copy->suiv;
}
printf("tete(liste) == %d \n", **(int**)tete(liste));
detruire(liste);
Relations r; relationInit(&r); Relations r; relationInit(&r);
// ajouter les entites de l'exemple // ajouter les entites de l'exemple
char *tabe[] ={"KARL","LUDOVIC","CELINE","CHLOE","GILDAS","CEDRIC","SEVERINE", char *tabe[] ={"KARL","LUDOVIC","CELINE","CHLOE","GILDAS","CEDRIC","SEVERINE",
...@@ -484,10 +461,8 @@ int main(){ ...@@ -484,10 +461,8 @@ int main(){
// explorer les relations // explorer les relations
printf("%s est en relation avec:\n", tabe[0]); printf("%s est en relation avec:\n", tabe[0]);
listeg br = en_relation(r, tabe[0]);
affichelg(en_relation(r, tabe[0]),afficheArc); affichelg(en_relation(r, tabe[0]),afficheArc);
printf("\n"); printf("\n");
/////
for (i = 0; i < 7; i++) for (j = i + 1; j < 10; j++){ for (i = 0; i < 7; i++) for (j = i + 1; j < 10; j++){
printf("<%s> et <%s> ont les relations communes:\n", tabe[i], tabe[j]); printf("<%s> et <%s> ont les relations communes:\n", tabe[i], tabe[j]);
listeg ch = chemin2(r, tabe[i], tabe[j]); listeg ch = chemin2(r, tabe[i], tabe[j]);
......
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