From a466d287a612c92b6c0bb74950cb31f3f0f3fee8 Mon Sep 17 00:00:00 2001
From: Abdul-Malik Elmurzaev <abdul-malik.elmurzaev@etu.unistra.fr>
Date: Sun, 5 May 2024 13:15:17 +0200
Subject: [PATCH] =?UTF-8?q?correction=20bugs=20car=20ils=20empechaient=20c?=
 =?UTF-8?q?hemin2=20de=20fonctionner.=20Toutes=20les=20fonctions=20dont=20?=
 =?UTF-8?q?chemin2=20sont=20v=C3=A9rifi=C3=A9s,=20aucune=20memory=20leak?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 relations.c | 51 +++++++++++++--------------------------------------
 1 file changed, 13 insertions(+), 38 deletions(-)

diff --git a/relations.c b/relations.c
index 90b8795..9ee896f 100644
--- a/relations.c
+++ b/relations.c
@@ -292,8 +292,10 @@ int compArc(void *a, void *string){
 void adjEntite(Relations g, char *nom, etype t){
 	listeg copy = g->listDeRelations;
 	while(copy != NULL){
-		if( ((Sommet)(copy->val))->x->nom == nom )
+		if( ((Sommet)(copy->val))->x->nom == nom ){
+			printf("check \n");
 			return;
+		}
 		copy = copy->suiv;
 	}
 	g->listDeRelations = adjqueue(g->listDeRelations, nouvSommet(creerEntite(nom, t)));
@@ -333,11 +335,12 @@ void adjRelation(Relations g, char *nom1, char *nom2, rtype id){
 // 4.1 listes de relations
 listeg en_relation(Relations g, char *x){
 	listeg res = listegnouv();
-	while(g->listDeRelations != NULL){
-		if(  strcmp( ((Sommet)(g->listDeRelations->val))->x->nom, x ) == 0 ){
-			return ((Sommet)(g->listDeRelations->val))->larcs;
+	listeg copyTete = g->listDeRelations;
+	while(copyTete != NULL){
+		if(  strcmp( ((Sommet)(copyTete->val))->x->nom, x ) == 0 ){
+			return ((Sommet)(copyTete->val))->larcs;
 		}
-		g->listDeRelations = g->listDeRelations->suiv;
+		copyTete = copyTete->suiv;
 	}
 	return res;
 }
@@ -364,18 +367,20 @@ listeg chemin2(Relations g, char *x, char *y){		// on renvoit une LISTE D ENTITE
 	listeg YEntites_copy = YEntites;
 	
 	while(XEntites_copy != NULL){
+		YEntites_copy = YEntites;
 		while(YEntites_copy != NULL){
 			//printf("a \n");
 			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 );
 			}
 			YEntites_copy = YEntites_copy->suiv;
 		}
 		XEntites_copy = XEntites_copy->suiv;
 	}
-	free(XEntites);
-	free(YEntites);
+	detruire(XEntites);
+	detruire(YEntites);
 	return RES;
 }
 // 4.2 verifier un lien de parente
@@ -432,34 +437,6 @@ void affiche_degre_relations(Relations r, char *x){
 int main(){
 	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);
 	// ajouter les entites de l'exemple
 	char *tabe[] ={"KARL","LUDOVIC","CELINE","CHLOE","GILDAS","CEDRIC","SEVERINE",
@@ -484,10 +461,8 @@ int main(){
 	
 	// explorer les relations
 	printf("%s est en relation avec:\n", tabe[0]);
-	listeg br = en_relation(r, tabe[0]);
 	affichelg(en_relation(r, tabe[0]),afficheArc);
 	printf("\n");
-	/////
 	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]);
 		listeg ch = chemin2(r, tabe[i], tabe[j]);
-- 
GitLab