foireux mais osef

master
esterfreyja 7 months ago
parent b33658edb2
commit bd5961ec11

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -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;

@ -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);

@ -0,0 +1,74 @@
#include "arbre.h"
#include <stdio.h>
#include <stdlib.h>
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;
}

@ -0,0 +1,9 @@
int my_strlen(char *str)
{
int len;
len = 0;
while (str[len] != '\0')
len++;
return (len);
}

@ -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;
Loading…
Cancel
Save