diff --git a/arbre_string/bin/exe b/arbre_string/bin/exe new file mode 100755 index 0000000..c5c9241 Binary files /dev/null and b/arbre_string/bin/exe differ diff --git a/arbre_string/obj/arbre.o b/arbre_string/obj/arbre.o new file mode 100644 index 0000000..9dda143 Binary files /dev/null and b/arbre_string/obj/arbre.o differ diff --git a/arbre_string/obj/menu.o b/arbre_string/obj/menu.o new file mode 100644 index 0000000..a623c63 Binary files /dev/null and b/arbre_string/obj/menu.o differ diff --git a/arbre_string/obj/my_strcmp.o b/arbre_string/obj/my_strcmp.o new file mode 100644 index 0000000..c69d637 Binary files /dev/null and b/arbre_string/obj/my_strcmp.o differ diff --git a/arbre_string/obj/my_strlen.o b/arbre_string/obj/my_strlen.o new file mode 100644 index 0000000..2495418 Binary files /dev/null and b/arbre_string/obj/my_strlen.o differ diff --git a/arbre_string/obj/test.o b/arbre_string/obj/test.o new file mode 100644 index 0000000..85b60c2 Binary files /dev/null and b/arbre_string/obj/test.o differ diff --git a/arbre_string/src/arbre.c b/arbre_string/src/arbre.c index 74e1f72..4d6aab0 100644 --- a/arbre_string/src/arbre.c +++ b/arbre_string/src/arbre.c @@ -104,7 +104,7 @@ int h(Arbre a) // { return -1; } - return 1 + max(h(ag(a)), h(ad(a))); + return 1 + (h(ag(a)) > h(ad(a)) ? h(ag(a)) : h(ad(a))); } bool f(Arbre a) // @@ -150,7 +150,7 @@ Arbre ed(Arbre a) // return a; } if(vide(ad(a))) - {max + { return a; } return ed(ad(a)); @@ -194,7 +194,7 @@ Arbre insf(Arbre a, char *x) // return reeq(a); } -Arbre supp(Arbre a, char x) // +Arbre supp(Arbre a, char *x) // { Arbre tmp; @@ -344,14 +344,14 @@ int deseq(Arbre a) return h(ag(a)) - h(ad(a)); } -Arbre insr(Arbre a, int x) +Arbre insr(Arbre a, char *x) { Couple c; c = couper(a, x); return reeq(e(c.c1, x, c.c2)); } -Couple couper(Arbre a, int x) +Couple couper(Arbre a, char *x) { Couple c; Couple d; @@ -368,7 +368,7 @@ Couple couper(Arbre a, int x) c.c2 = ad(a); return c; } - if(my_strcmp(x < r(a)) < 0) + if(my_strcmp(x, r(a)) < 0) { d = couper(ag(a), x); c.c1 = d.c1; diff --git a/arbre_string/src/arbre.h b/arbre_string/src/arbre.h index c274854..30778d0 100644 --- a/arbre_string/src/arbre.h +++ b/arbre_string/src/arbre.h @@ -34,10 +34,10 @@ int h(Arbre a);// void viderArbre(Arbre a);// int nn(Arbre a);// bool egarb(Arbre a, Arbre b);// -Arbre insf(Arbre a, int x);// -Arbre supp(Arbre a, int x);// +Arbre insf(Arbre a, char *x);// +Arbre supp(Arbre a, char *x);// Arbre oterMax(Arbre a);// -Arbre rech(Arbre a, int x);// +Arbre rech(Arbre a, char *x);// bool trie(Arbre a);// Arbre rd(Arbre a);// Arbre rg(Arbre a);// @@ -45,7 +45,8 @@ Arbre rgd(Arbre a);// Arbre rdg(Arbre a);// Arbre reeq(Arbre a);// int deseq(Arbre a);// -Arbre insr(Arbre a, int x);// -Couple couper(Arbre a, int x);// +Arbre insr(Arbre a, char *x);// +Couple couper(Arbre a, char *x);// Arbre oterMin(Arbre a);// int my_strcmp(char *s1, char *s2); +int my_strlen(char *str); diff --git a/arbre_string/src/menu.c b/arbre_string/src/menu.c new file mode 100644 index 0000000..f16be38 --- /dev/null +++ b/arbre_string/src/menu.c @@ -0,0 +1,74 @@ +#include "arbre.h" +#include +#include + + +void saisie(char **mot) +{ + char *buffer = NULL; + size_t size = 0; + size_t len = 0; + char c; + + printf("Saisissez votre mot\n"); + while((c = getchar()) != '\n' && c != EOF); + getline(&buffer, &size, stdin); + len = my_strlen(buffer); + if(buffer[len - 1] == '\n') + { + buffer[len - 1] = '\0'; + len--; + } + *mot = realloc(buffer, len + 1); + if(*mot == NULL) + { + free(buffer); + printf("Erreur de réallocation de mémoire\n"); + exit(1); + } + return; +} + +int main(void) +{ + char h[10]; + Arbre Arbre1 = arbreNouv(); + char *mot = NULL; + + while(1) + { + printf("String B-tree\n1 - Afficher\n2 - Ajouter\n3 - Rechercher\n4 - Supprimer\nAciaobonsoir - Quitter\n"); + scanf("%s", h); + if(my_strcmp(h, "2") == 0) + { + saisie(&mot); + Arbre1 = insf(Arbre1, mot); + afficherArbre(Arbre1); + } + else if(my_strcmp(h, "1") == 0) + { + afficherArbre(Arbre1); + } + else if(my_strcmp(h, "3") == 0) + { + saisie(&mot); + afficherArbre(rech(Arbre1, mot)); + } + else if(my_strcmp(h, "4") == 0) + { + saisie(&mot); + supp(Arbre1, mot); + afficherArbre(Arbre1); + + } + else if(my_strcmp(h, "Aciaobonsoir") == 0) + { + break; + } + else + { + printf("choix invalide\n"); + } + } + return 0; +} diff --git a/arbre_string/src/my_strlen.c b/arbre_string/src/my_strlen.c new file mode 100644 index 0000000..02f10d8 --- /dev/null +++ b/arbre_string/src/my_strlen.c @@ -0,0 +1,9 @@ +int my_strlen(char *str) +{ + int len; + + len = 0; + while (str[len] != '\0') + len++; + return (len); +} diff --git a/arbre_string/src/test.c b/arbre_string/src/test.c.cul similarity index 66% rename from arbre_string/src/test.c rename to arbre_string/src/test.c.cul index a02a228..9263f76 100644 --- a/arbre_string/src/test.c +++ b/arbre_string/src/test.c.cul @@ -31,15 +31,16 @@ void testTri(bool a) int main(void) { Arbre Arbre1 = arbreNouv(); - Arbre1 = insf(Arbre1, 11); - Arbre1 = insf(Arbre1, 10); - Arbre1 = insf(Arbre1, 9); - Arbre1 = insf(Arbre1, 8); - Arbre1 = insf(Arbre1, 7); - Arbre1 = insf(Arbre1, 6); - Arbre1 = insf(Arbre1, 5); + Arbre1 = insf(Arbre1, "aerg"); + Arbre1 = insf(Arbre1, "bsert"); + Arbre1 = insf(Arbre1, "weart"); + Arbre1 = insf(Arbre1, "zdfrtyj"); + Arbre1 = insf(Arbre1, "aergt"); + Arbre1 = insf(Arbre1, "dftyj"); + Arbre1 = insf(Arbre1, "dr6tj"); afficherArbre(Arbre1); oterMin(Arbre1); + printf("\n\n"); afficherArbre(Arbre1); viderArbre(Arbre1); return 0;