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

fonction en_relation marche correctement, chemin2 pas encore

parent 7d35050c
Branches
1 merge request!5fonctions jusqu'à chemin2 incluse sont vérifiées. Aucune memory leak
......@@ -47,6 +47,28 @@ typedef struct s_node{
void *val; // pointeur vers objet quelconque
struct s_node *suiv;
}*listeg;
#define LONG_NOM_MAX 64
typedef enum{
PERSONNE=1, OBJET, ADRESSE, VILLE
}etype;
typedef struct s_entite{
char nom[LONG_NOM_MAX]; // le nom de l entite p.ex " Peugeot 106 "
etype ident; // l identifiant associe, p.ex OBJET
}*Entite;
//3.1 les structures de donnees
typedef struct s_sommet{
struct s_node* larcs;
Entite x;
}*Sommet;
typedef struct s_arc{
rtype t;
struct s_entite* x;
}*Arc;
typedef struct s_relations{
listeg listDeRelations;
}*Relations;
listeg listegnouv(){
return NULL;
......@@ -116,22 +138,21 @@ void detruire(listeg lst){
free(lst);
lst = copy;
}
}
}//
listeg rech(listeg lst, void *x, int(*comp)(void *, void *)){
listeg resultat = listegnouv();
listeg copy = lst;
while(copy != NULL){
if( comp(x, copy->val) ){
resultat = adjqueue(resultat, copy->val);
while(lst != NULL){
if( comp(lst->val, x) ){
resultat = adjqueue(resultat, lst->val);
}
copy = copy->suiv;
lst = lst->suiv;
}
return resultat;
}
////////////////////////////////////////
// Exercice 3: Construction du graphe
/*
#define LONG_NOM_MAX 64
typedef enum{
PERSONNE=1, OBJET, ADRESSE, VILLE
......@@ -154,7 +175,7 @@ typedef struct s_arc{
typedef struct s_relations{
listeg listDeRelations;
}*Relations;
*/
//3.2 les constructeurs
Entite creerEntite(char *s, etype e){
Entite newEntity = malloc(sizeof(struct s_entite));
......@@ -292,11 +313,46 @@ void adjRelation(Relations g, char *nom1, char *nom2, rtype id){
// 4.1 listes de relations
listeg en_relation(Relations g, char *x){
listeg liste = g->listDeRelations;
liste = rech(liste, x, compSommet);
listeg liste = listegnouv();
liste = rech(g->listDeRelations, x, &compSommet);
listeg res = ((Sommet)(liste->val))->larcs;
return res;
}
listeg chemin2(Relations g, char *x, char *y){
return NULL;
listeg chemin2(Relations g, char *x, char *y){ // on renvoit une LISTE D ENTITES
listeg LarcsOfX = en_relation(g, x);
listeg LarcsOfY = en_relation(g, y);
listeg XEntites = listegnouv(); // on va stocker toutes les entites en relation avec x et y
listeg YEntites = listegnouv();
listeg RES = listegnouv(); // puis mettres dans RES les entités en commun sauf x et y
listeg LarcsOfX_copy = LarcsOfX;
listeg LarcsOfY_copy = LarcsOfY;
while(LarcsOfX_copy != NULL){
XEntites = adjqueue(XEntites, ((Arc)(LarcsOfX_copy->val))->x );
LarcsOfX_copy = LarcsOfX_copy->suiv;
}
while(LarcsOfY_copy != NULL){
YEntites = adjqueue(YEntites, ((Arc)(LarcsOfY_copy->val))->x );
LarcsOfY_copy = LarcsOfY_copy->suiv;
}
listeg XEntites_copy = XEntites;
listeg YEntites_copy = YEntites;
while(XEntites_copy != NULL){
while(YEntites_copy != NULL){
printf("a \n");
if( compEntite(XEntites_copy->val, ((Entite)(YEntites_copy->val))->nom) ){
RES = adjqueue(RES, XEntites_copy->val);
printf(" ___________ %s \n", ((Entite)(RES->val))->nom );
}
YEntites_copy = YEntites_copy->suiv;
}
XEntites_copy = XEntites_copy->suiv;
}
free(XEntites);
free(YEntites);
return RES;
}
// 4.2 verifier un lien de parente
// PRE CONDITION: strcmp(x,y)!=0
......@@ -405,19 +461,15 @@ int main(){
affichelg( ((Sommet)(r->listDeRelations->val))->larcs, afficheArc );
printf("\n %s \n", ((Arc)(((Sommet)(r->listDeRelations->val))->larcs->val))->x->nom );
relationFree(&r);
return 0;//////
//relationFree(&r);
// 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++)
{
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]);
affichelg(ch, afficheEntite);
......@@ -426,6 +478,7 @@ int main(){
}
printf("\n\n");
return 0; /////
for (i = 0; i < 10; i++) for (j = i + 1; j < 10; j++)
{
printf("<%s> et <%s> ont lien de parente: %s\n",
......
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