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.
@ -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);
|
||||
}
|
Loading…
Reference in new issue