diff --git a/relations.c b/relations.c index d3b49d87ceaf9e282c849e4786364eb793f814c6..d98716437bcb85efb3a911b165299e22fa18cd49 100644 --- a/relations.c +++ b/relations.c @@ -17,17 +17,54 @@ typedef enum{ CHEF, COLLEGUE, LOCATAIRE, TRAVAILLE, PROPRIETAIRE, SITUE, DECOUVERT }rtype; -bool est_lien_parente(rtype id){ - return false; +bool est_lien_parente(rtype id){ + return (id == FRERE || id == COUSIN || id == PARENT || id == ONCLE); } -bool est_lien_professionel(rtype id){ - return false; +bool est_lien_professionel(rtype id){ + return (id == CHEF || id == COLLEGUE); } bool est_lien_connaissance(rtype id){ - return false; + return (id == EPOUX || id == AMI || id == CONNAIT || id == VIT); +} + +typedef struct snoeud{ + int type; + int val[3]; + struct snoeuf* fils[4]; +}arbre, *Arbre234; + + +typedef struct relations{ + char* leurRelation[17]; +}RelationsTable; + +RelationsTable* newRelationsTable(){ + RelationsTable* r = malloc(sizeof(RelationsTable)); + r->leurRelation[0] = "NULL"; + r->leurRelation[1] = "NULL"; + return r; +} +RelationsTable* addRelationsTable(RelationsTable* r, char* name, int id){ // name of their relation + r->leurRelation[id] = name; + return r; +} +RelationsTable* completeTheRelationsTable(){ + RelationsTable* r = newRelationsTable(); + char* n2 = " frère ou soeur de "; char* n3 = "cousin ou cousine de "; char* n4 = "père ou mère "; + char* n5 = " oncle ou tante de "; char* n6 = "époux ou épouse de "; char* n7 = "ami de "; + char* n8 = " vit avec "; char* n9 = " connait "; char* n10 = " supérieur de "; + char* n11 = " collègue de "; char* n12 = " locataire de "; char* n13 = " travaille à "; + char* n14 = " propriétaire de "; char* n15 = " situé à "; char* n16 = " découvert à "; + char* table[15] = {n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16}; + for(int i=0; i<15; i++){ + r = addRelationsTable(r, table[i], i+2); + } + return r; } + char* toStringRelation(rtype id){ - return ""; + RelationsTable* r = completeTheRelationsTable(); + return r->leurRelation[id]; } //////////////////////////////////////// @@ -42,28 +79,73 @@ listeg listegnouv(){ return NULL; } listeg adjtete(listeg lst, void *x){ - return lst; + listeg new = malloc(sizeof(struct s_node)); + new->val = x; + new->suiv = lst; + return new; } listeg adjqueue(listeg lst, void *x){ + listeg new = malloc(sizeof(struct s_node)); + new->val = x; + new->suiv = NULL; + if( lst != NULL ){ + listeg copy = lst; + while(copy->suiv != NULL){ + copy = copy->suiv; + } + copy->suiv = new; + }else{ + return new; + } return lst; } listeg suptete(listeg lst){ - return lst; + listeg deuxieme = lst->suiv; + free(lst); + return deuxieme; } void *tete(listeg lst){ - return NULL; + return lst->val; } int longueur(listeg lst){ - return -1; + int res = 0; + if( lst == NULL ) + return res; + res++; + listeg copy = lst; + while(copy->suiv != NULL){ + copy = copy->suiv; + res++; + } + return res; } bool estvide(listeg lst){ - return false; + return lst == NULL; } void detruire(listeg lst){ - + if( estvide(lst) ) + return; + if(lst->suiv != NULL){ + free(lst); + return; + } + listeg copy = lst; + while(copy != NULL){ + listeg deathrowInmate = copy; + copy = copy->suiv; + free(lst); + } } listeg rech(listeg lst, void *x, int(*comp)(void *, void *)){ + listeg copy = lst; + while(copy != NULL){ + if( comp(x, copy->val) ){ + return lst; + }else{ + copy = copy->suiv; + } + } return NULL; } @@ -186,11 +268,43 @@ 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); + return 0; + + Relations r; relationInit(&r); // ajouter les entites de l'exemple char *tabe[] ={"KARL","LUDOVIC","CELINE","CHLOE","GILDAS","CEDRIC","SEVERINE", "PEUGEOT 106" ,"1, RUE DE LA RUE","STRASBOURG" }; - for (i = 0; i < 7; i++) adjEntite(r, tabe[i], PERSONNE); + for (i = 0; i < 7; i++) + adjEntite(r, tabe[i], PERSONNE); adjEntite(r, tabe[7], OBJET); adjEntite(r, tabe[8], ADRESSE); adjEntite(r, tabe[9], VILLE);