Commit cb716d775c53286f16db1076364159142ec25dd0

Authored by Vincent Benoist
1 parent 37a5f1f0

SD jusqua hachage

TpSD3_Karatsuba/.Karatsuba.c.kate-swp renamed to SD/TP3_Karatsuba/.Karatsuba.c.kate-swp
No preview for this file type
TpSD3_Karatsuba/Elementaire.stats renamed to SD/TP3_Karatsuba/Elementaire.stats
TpSD3_Karatsuba/Karatsuba.c renamed to SD/TP3_Karatsuba/Karatsuba.c
TpSD3_Karatsuba/Karatsuba.stats renamed to SD/TP3_Karatsuba/Karatsuba.stats
TpSD3_Karatsuba/a.out renamed to SD/TP3_Karatsuba/a.out
No preview for this file type
SD/TP5_ABR/ABR.dot 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +digraph G {
  2 +14 -> 7 [label="gauche"];
  3 +7 -> 3 [label="gauche"];
  4 +14 -> 88 [label="droit"];
  5 +88 -> 51 [label="gauche"];
  6 +51 -> 17 [label="gauche"];
  7 +51 -> 53 [label="droit"];
  8 +}
... ...
SD/TP5_ABR/ABR.pdf 0 → 100644
No preview for this file type
SD/TP5_ABR/Makefile 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +.PHONY: clean,real-clean
  2 +LD = gcc
  3 +CC = gcc
  4 +CFLAGS = -Wall -W
  5 +SRC=$(wildcard *.c)
  6 +OBJ=$(SRC:.c=.o)
  7 +prog : $(OBJ)
  8 + $(LD) -o $@ $^
  9 +
  10 +%.o : %.c
  11 + $(CC) $(CFLAGS) -c $^
  12 +
  13 +clean :
  14 + rm -f *.o
  15 +
  16 +real-clean : clean
  17 + rm -f prog
... ...
SD/TP5_ABR/a.out 0 → 100755
No preview for this file type
SD/TP5_ABR/abr.c 0 → 100644
... ... @@ -0,0 +1,143 @@
  1 +#include <stdio.h>
  2 +#include <stdlib.h>
  3 +#include <assert.h>
  4 +#include "abr.h"
  5 +
  6 +
  7 +/*
  8 + struct abr {
  9 + struct abr* gauche;
  10 + int valeur;
  11 + struct abr* droit;
  12 +};
  13 +*/
  14 +static struct abr* new_feuille (int x){
  15 +
  16 + struct abr* F;
  17 +
  18 + F = (struct abr*)malloc (sizeof (struct abr));
  19 + F->gauche = NIL;
  20 + F->valeur = x;
  21 + F->droit = NIL;
  22 + return F;
  23 +}
  24 +
  25 +
  26 +struct abr* ajout_abr_rec (int x, struct abr* A){
  27 + if (A == NIL)
  28 + return new_feuille (x);
  29 + else if (x < A->valeur)
  30 + A->gauche = ajout_abr_rec (x, A->gauche);
  31 + else
  32 + A->droit = ajout_abr_rec (x, A->droit);
  33 + return A;
  34 +}
  35 +
  36 +int max( int a, int b){
  37 +
  38 + if(a>b){
  39 + return a;
  40 + }
  41 + return b;
  42 +}
  43 +
  44 +int hauteur_abr( struct abr* A){
  45 +
  46 + if(A == NIL){
  47 + return -1;
  48 + }
  49 + return max(hauteur_abr(A->gauche),hauteur_abr(A->droit))+1;
  50 +
  51 +}
  52 +
  53 +
  54 +bool recherche_abr_rec (int x, struct abr* A){
  55 + bool b = false;
  56 + if (A == NIL){
  57 + return b;
  58 + } else if ( x == A->valeur ){
  59 + return true;
  60 + } else if (x < A->valeur){
  61 + b=recherche_abr_rec (x, A->gauche);
  62 + } else{
  63 + b=recherche_abr_rec (x, A->droit);
  64 + }
  65 + return b;
  66 +}
  67 +
  68 +
  69 +static void affiche_abr (struct abr* A){
  70 + if( A!= NIL){
  71 + affiche_abr(A->gauche);
  72 + printf("- %d ", A-> valeur);
  73 + affiche_abr(A->droit);
  74 + }
  75 +
  76 +}
  77 +
  78 +
  79 +void imprime_abr (struct abr* A){
  80 + printf("Valeurs de l'arbre: \n");
  81 + affiche_abr(A);
  82 + printf(" -\n");
  83 +}
  84 +
  85 +
  86 +static void affiche_abrV2 (struct abr* A, int profondeur){
  87 + if( A!= NIL){
  88 + int i = 0;
  89 + for(i=0; i<=profondeur; i++){
  90 + printf("\t");
  91 + }
  92 +
  93 + printf("%d\n ", A-> valeur);
  94 + affiche_abrV2(A->droit, profondeur+1);
  95 + affiche_abrV2(A->gauche, profondeur+1);
  96 + }
  97 +
  98 +}
  99 +
  100 +void imprime_abrV2 (struct abr* A){
  101 + printf("Valeurs de l'arbre: \n");
  102 + affiche_abrV2(A, 0);
  103 + printf("\n");
  104 +}
  105 +
  106 +void clear_abr (struct abr* A)
  107 +{
  108 + if (A != NIL)
  109 + { clear_abr (A->gauche);
  110 + clear_abr (A->droit);
  111 + free (A);
  112 + }
  113 +}
  114 +
  115 +void imprimeArbreDot( struct abr* A, FILE* f){
  116 + if(A->gauche != NIL){
  117 + fprintf(f,"%d -> %d [label=\"gauche\"];\n", A->valeur, A->gauche->valeur);
  118 + imprimeArbreDot(A->gauche,f);
  119 + }
  120 + if(A->droit != NIL){
  121 + fprintf(f,"%d -> %d [label=\"droit\"];\n", A->valeur, A->droit->valeur);
  122 + imprimeArbreDot(A->droit,f);
  123 + }
  124 +}
  125 +
  126 +
  127 +void imprimeDot( struct abr* A){
  128 + FILE* f;
  129 + f = fopen("ABR.dot", "w");
  130 + fprintf(f,"digraph G {\n");
  131 + if(A==NIL){
  132 + fprintf(f,"NIL\n");
  133 + }else if (A->gauche == NIL && A->droit == NIL){
  134 + fprintf(f,"%d\n", A->valeur);
  135 + }else {
  136 + imprimeArbreDot(A,f);
  137 + }
  138 + fprintf(f,"}\n");
  139 + fclose(f);
  140 + system("dot -Tpdf ABR.dot -GRANKDIR=LR -o ABR.pdf");
  141 + system("evince ABR.pdf &");
  142 +}
  143 +
... ...
SD/TP5_ABR/abr.h 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +#include <stdbool.h>
  2 +
  3 +struct abr {
  4 + struct abr* gauche;
  5 + int valeur;
  6 + struct abr* droit;
  7 +};
  8 +
  9 +#define NIL (struct abr*)0
  10 +
  11 +
  12 +extern struct abr* ajout_abr_rec (int, struct abr*);
  13 +
  14 +/* Calcule la hauteur d'un abr*/
  15 +extern int hauteur_abr( struct abr*);
  16 +
  17 +extern bool recherche_abr_rec (int, struct abr*);
  18 +
  19 +extern void imprime_abr (struct abr*);
  20 +
  21 +extern void imprime_abrV2 (struct abr*);
  22 +
  23 +extern void clear_abr (struct abr*);
... ...
SD/TP5_ABR/abr.o 0 → 100644
No preview for this file type
SD/TP5_ABR/arbres correction/abr.c 0 → 100644
... ... @@ -0,0 +1,96 @@
  1 +#include <stdio.h>
  2 +#include <stdlib.h>
  3 +#include <assert.h>
  4 +#include "abr.h"
  5 +
  6 +bool recherche_abr_iter (int x, struct abr* A0)
  7 +{ struct abr* A; // curseur pour se déplacer dans A0
  8 + bool trouve;
  9 +
  10 + A = A0;
  11 + trouve = false;
  12 + while (A != NIL && !trouve)
  13 + {
  14 + if (A->valeur == x)
  15 + trouve = true;
  16 + else if (A->valeur < x)
  17 + A = A->droit;
  18 + else
  19 + A = A->gauche;
  20 + }
  21 + return trouve;
  22 +}
  23 +
  24 +bool recherche_abr_rec (int x, struct abr* A)
  25 +{
  26 + if (A == NIL)
  27 + return false;
  28 + else if (A->valeur == x)
  29 + return true;
  30 + else if (A->valeur < x)
  31 + return recherche_abr_rec (x, A->droit);
  32 + else
  33 + return recherche_abr_rec (x, A->gauche);
  34 +}
  35 +
  36 +static struct abr* new_feuille (int x)
  37 +{ struct abr* F;
  38 +
  39 + F = (struct abr*)malloc (sizeof (struct abr));
  40 + F->gauche = NIL;
  41 + F->valeur = x;
  42 + F->droit = NIL;
  43 + return F;
  44 +}
  45 +
  46 +struct abr* ajout_abr_iter (int x, struct abr* A0)
  47 +{
  48 + if (A0 == NIL)
  49 + return new_feuille (x);
  50 + else
  51 + { struct abr* prec = NIL;
  52 + struct abr* cour = A0;
  53 + while (cour != NIL)
  54 + { prec = cour;
  55 + if (cour->valeur < x)
  56 + cour = cour->droit;
  57 + else
  58 + cour = cour->gauche;
  59 + }
  60 + if (prec->valeur < x)
  61 + prec->droit = new_feuille (x);
  62 + else
  63 + prec->gauche = new_feuille (x);
  64 + return A0;
  65 + }
  66 +}
  67 +
  68 +struct abr* ajout_abr_rec (int x, struct abr* A)
  69 +{
  70 + if (A == NIL)
  71 + return new_feuille (x);
  72 + else if (x < A->valeur)
  73 + A->gauche = ajout_abr_rec (x, A->gauche);
  74 + else
  75 + A->droit = ajout_abr_rec (x, A->droit);
  76 + return A;
  77 +}
  78 +
  79 +void clear_abr (struct abr* A)
  80 +{
  81 + if (A != NIL)
  82 + { clear_abr (A->gauche);
  83 + clear_abr (A->droit);
  84 + free (A);
  85 + }
  86 +}
  87 +
  88 +void imprime_abr (struct abr* A)
  89 +{
  90 + if (A != NIL)
  91 + { imprime_abr (A->gauche);
  92 + printf ("%d\n", A->valeur);
  93 + imprime_abr (A->droit);
  94 + }
  95 +}
  96 +
... ...
SD/TP5_ABR/arbres correction/abr.h 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +// abr.h
  2 +
  3 +#include <stdbool.h>
  4 +
  5 +struct abr {
  6 + struct abr* gauche; // ne contient que des entiers < valeur
  7 + int valeur;
  8 + struct abr* droit; // ne contient que des entiers > valeur
  9 +};
  10 +
  11 +#define NIL (struct abr*)0
  12 +
  13 +extern struct abr* ajout_abr_iter (int, struct abr*);
  14 +
  15 +extern struct abr* ajout_abr_rec (int, struct abr*);
  16 +
  17 +extern bool recherche_abr_iter (int, struct abr*);
  18 +
  19 +extern bool recherche_abr_rec (int, struct abr*);
  20 +
  21 +extern void imprime_abr (struct abr*);
  22 +
  23 +extern void clear_abr (struct abr*);
  24 +
  25 +
... ...
SD/TP5_ABR/arbres correction/abr.o 0 → 100644
No preview for this file type
SD/TP5_ABR/arbres correction/main.c 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +#include <stdio.h>
  2 +#include "abr.h"
  3 +
  4 +int main ()
  5 +{ int T [] = { 17, 43, 109, 56, 8, 11 };
  6 + int i, n = sizeof(T)/sizeof(int);
  7 +
  8 + struct abr* A;
  9 +
  10 + A = NIL;
  11 + for (i = 0; i < n; i++)
  12 + { A = ajout_abr_rec (T[i], A);
  13 + }
  14 + if (recherche_abr_rec (14, A))
  15 + printf ("14 est présent dans A\n");
  16 + else
  17 + printf ("14 est absent de A\n");
  18 + imprime_abr (A);
  19 + clear_abr (A);
  20 + return 0;
  21 +}
  22 +
... ...
SD/TP5_ABR/arbres correction/main.o 0 → 100644
No preview for this file type
SD/TP5_ABR/arbres correction/prog 0 → 100755
No preview for this file type
SD/TP5_ABR/esperanto/Makefile 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +.PHONY: clean,real-clean
  2 +LD = gcc
  3 +CC = gcc
  4 +CFLAGS = -Wall -W
  5 +SRC=$(wildcard *.c)
  6 +OBJ=$(SRC:.c=.o)
  7 +prog : $(OBJ)
  8 + $(LD) -o $@ $^
  9 +
  10 +%.o : %.c
  11 + $(CC) $(CFLAGS) -c $^
  12 +
  13 +clean :
  14 + rm -f *.o
  15 +
  16 +real-clean : clean
  17 + rm -f prog
... ...
SD/TP5_ABR/esperanto/abr.c 0 → 100644
... ... @@ -0,0 +1,143 @@
  1 +#include <stdio.h>
  2 +#include <stdlib.h>
  3 +#include <assert.h>
  4 +#include "abr.h"
  5 +
  6 +
  7 +/*
  8 + struct abr {
  9 + struct abr* gauche;
  10 + int valeur;
  11 + struct abr* droit;
  12 +};
  13 +*/
  14 +static struct abr* new_feuille (wchar_t clef, wchar_t satellite){
  15 +
  16 + struct abr* F;
  17 +
  18 + F = (struct abr*)malloc (sizeof (struct abr));
  19 + F->gauche = NIL;
  20 + F->clef = x;
  21 + F->droit = NIL;
  22 + return F;
  23 +}
  24 +
  25 +
  26 +struct abr* ajout_abr_rec (wchar_t clef, wchar_t satellite, struct abr* A){
  27 + if (A == NIL)
  28 + return new_feuille (x);
  29 + else if (wcscmp(clef,A->clef)== -1)//
  30 + A->gauche = ajout_abr_rec (clef, satellite, A->gauche);
  31 + else
  32 + A->droit = ajout_abr_rec (clef, satellite, A->droit);
  33 + return A;
  34 +}
  35 +
  36 +int max( int a, int b){
  37 +
  38 + if(a>b){
  39 + return a;
  40 + }
  41 + return b;
  42 +}
  43 +
  44 +int hauteur_abr( struct abr* A){
  45 +
  46 + if(A == NIL){
  47 + return -1;
  48 + }
  49 + return max(hauteur_abr(A->gauche),hauteur_abr(A->droit))+1;
  50 +
  51 +}
  52 +
  53 +
  54 +wchar_t* recherche_abr_rec (wchar_t* x, struct abr* A){
  55 + wchar_t* res = (wchar_t*)0;
  56 + if (A == NIL){
  57 + return res;
  58 + } else if (wcscmp(x,A->clef)== 0 ){
  59 + return x;
  60 + } else if (wcscmp(x,A->clef)== -1){
  61 + wcscpy(res,recherche_abr_rec (x, A->gauche));
  62 + } else{
  63 + wcscpy(res,recherche_abr_rec (x, A->gauche));
  64 + }
  65 + return res;
  66 +}
  67 +
  68 +
  69 +static void affiche_abr (struct abr* A){
  70 + if( A!= NIL){
  71 + affiche_abr(A->gauche);
  72 + printf("- %d ", A-> valeur);
  73 + affiche_abr(A->droit);
  74 + }
  75 +
  76 +}
  77 +
  78 +
  79 +void imprime_abr (struct abr* A){
  80 + printf("Valeurs de l'arbre: \n");
  81 + affiche_abr(A);
  82 + printf(" -\n");
  83 +}
  84 +
  85 +
  86 +static void affiche_abrV2 (struct abr* A, int profondeur){
  87 + if( A!= NIL){
  88 + int i = 0;
  89 + for(i=0; i<=profondeur; i++){
  90 + printf("\t");
  91 + }
  92 +
  93 + printf("%d\n ", A-> valeur);
  94 + affiche_abrV2(A->droit, profondeur+1);
  95 + affiche_abrV2(A->gauche, profondeur+1);
  96 + }
  97 +
  98 +}
  99 +
  100 +void imprime_abrV2 (struct abr* A){
  101 + printf("Valeurs de l'arbre: \n");
  102 + affiche_abrV2(A, 0);
  103 + printf("\n");
  104 +}
  105 +
  106 +void clear_abr (struct abr* A)
  107 +{
  108 + if (A != NIL)
  109 + { clear_abr (A->gauche);
  110 + clear_abr (A->droit);
  111 + free (A);
  112 + }
  113 +}
  114 +/*
  115 +void imprimeArbreDot( struct abr* A, FILE* f){
  116 + if(A->gauche != NIL){
  117 + fprintf(f,"%d -> %d [label=\"gauche\"];\n", A->valeur, A->gauche->valeur);
  118 + imprimeArbreDot(A->gauche,f);
  119 + }
  120 + if(A->droit != NIL){
  121 + fprintf(f,"%d -> %d [label=\"droit\"];\n", A->valeur, A->droit->valeur);
  122 + imprimeArbreDot(A->droit,f);
  123 + }
  124 +}
  125 +
  126 +
  127 +void imprimeDot( struct abr* A){
  128 + FILE* f;
  129 + f = fopen("ABR.dot", "w");
  130 + fprintf(f,"digraph G {\n");
  131 + if(A==NIL){
  132 + fprintf(f,"NIL\n");
  133 + }else if (A->gauche == NIL && A->droit == NIL){
  134 + fprintf(f,"%d\n", A->valeur);
  135 + }else {
  136 + imprimeArbreDot(A,f);
  137 + }
  138 + fprintf(f,"}\n");
  139 + fclose(f);
  140 + system("dot -Tpdf ABR.dot -GRANKDIR=LR -o ABR.pdf");
  141 + system("evince ABR.pdf &");
  142 +}
  143 +*/
... ...
SD/TP5_ABR/esperanto/abr.h 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +#include <stdbool.h>
  2 +#include <wchar.h>
  3 +
  4 +typedef wchar_t wstring [MAXLEN];
  5 +
  6 +struct abr {
  7 + struct abr* gauche;
  8 + wchar_t clef;
  9 + wchar_t satellite;
  10 + struct abr* droit;
  11 +};
  12 +
  13 +#define NIL (struct abr*)0
  14 +
  15 +
  16 +extern struct abr* ajout_abr_rec (wchar_t, wchar_t , struct abr*);
  17 +
  18 +/* Calcule la hauteur d'un abr*/
  19 +extern int hauteur_abr( struct abr*);
  20 +
  21 +extern bool recherche_abr_rec (int, struct abr*);
  22 +
  23 +extern void imprime_abr (struct abr*);
  24 +
  25 +extern void imprime_abrV2 (struct abr*);
  26 +
  27 +extern void clear_abr (struct abr*);
... ...
SD/TP5_ABR/esperanto/main.c 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +#include <stdio.h>
  2 +#include "abr.h"
  3 +
  4 +int main (){
  5 + struct abr* racine;
  6 + int x;
  7 + racine = NIL;
  8 + scanf ("%d", &x);
  9 + while (x != -1) {
  10 + racine = ajout_abr_rec(x, racine);
  11 + imprime_abrV2(racine);
  12 + //imprime_abr(racine);
  13 + scanf("%d", &x);
  14 + }
  15 + printf("%s\n", recherche_abr_rec (3, racine) ? "La valeur est bien présente" : "Val introuvée");
  16 +
  17 + printf ("la hauteur de l'ABR est %d\n", hauteur_abr(racine));
  18 + // imprimeDot(racine);
  19 + // printf ("le nombre de noeuds de l'ABR est %d\n",nombre_noeuds_abr (racine));
  20 + clear_abr (racine);
  21 + return 0;
  22 +}
... ...
SD/TP5_ABR/esperanto/values 0 → 100644
... ... @@ -0,0 +1 @@
  1 +14 7 88 51 17 53 3 -1
... ...
SD/TP5_ABR/main.c 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +#include <stdio.h>
  2 +#include "abr.h"
  3 +
  4 +int main (){
  5 + struct abr* racine;
  6 + int x;
  7 + racine = NIL;
  8 + scanf ("%d", &x);
  9 + while (x != -1) {
  10 + racine = ajout_abr_rec(x, racine);
  11 + imprime_abrV2(racine);
  12 + //imprime_abr(racine);
  13 + scanf("%d", &x);
  14 + }
  15 + printf("%s\n", recherche_abr_rec (3, racine) ? "La valeur est bien présente" : "Val introuvée");
  16 +
  17 + printf ("la hauteur de l'ABR est %d\n", hauteur_abr(racine));
  18 + imprimeDot(racine);
  19 + // printf ("le nombre de noeuds de l'ABR est %d\n",nombre_noeuds_abr (racine));
  20 + clear_abr (racine);
  21 + return 0;
  22 +}
... ...
SD/TP5_ABR/main.o 0 → 100644
No preview for this file type
SD/TP5_ABR/prog 0 → 100755
No preview for this file type
SD/TP5_ABR/values 0 → 100644
... ... @@ -0,0 +1 @@
  1 +14 7 88 51 17 53 3 -1
... ...
SD/TP6_Hachage/Makefile 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +.PHONY: clean,real-clean
  2 +LD = gcc
  3 +CC = gcc
  4 +CFLAGS =
  5 +SRC=$(wildcard *.c)
  6 +OBJ=$(SRC:.c=.o)
  7 +prog : $(OBJ)
  8 + $(LD) -o $@ $^
  9 +
  10 +%.o : %.c
  11 + $(CC) $(CFLAGS) -c $^
  12 +
  13 +clean :
  14 + rm -f *.o
  15 +
  16 +real-clean : clean
  17 + rm -f prog
... ...
SD/TP6_Hachage/hachage_simple.c 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +#include "hachage_simple.h"
  2 +#include "liste_double.h"
  3 +#include <stdio.h>
  4 +#include <stdlib.h>
  5 +#include <assert.h>
  6 +#include <stdbool.h>
  7 +
  8 +
  9 +
  10 +void init_table (struct table* T, fonction_hachage* H){
  11 + int i = 0;
  12 + for(i=0; i<N;i++){
  13 + init_liste_double (&T->tab[N].L);
  14 + }
  15 +}
  16 +
  17 +void clear_table (struct table* T){
  18 + int i = 0;
  19 + for(i=0; i<N;i++){
  20 + clear_liste_double (&T->tab[N].L);
  21 + }
  22 +
  23 +
  24 +}
  25 +
  26 +void enregistrer_table (struct table* T, double d){
  27 +
  28 +}
  29 +
  30 +bool rechercher_table (struct table* T, double d){
  31 + return true;
  32 +}
  33 +
  34 +void imprimer_table (struct table* T){
  35 +
  36 +}
  37 +
... ...
SD/TP6_Hachage/hachage_simple.h 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +/* hachage_simple.h */
  2 +#include "liste_double.h"
  3 +#include <stdbool.h>
  4 +
  5 +struct alveole {
  6 + struct liste_double L;
  7 +};
  8 +
  9 +typedef int fonction_hachage (double);
  10 +
  11 +#define N 10
  12 +struct table {
  13 + struct alveole tab [N];
  14 + fonction_hachage* hash;
  15 +};
  16 +
  17 +extern void init_table (struct table*, fonction_hachage*);
  18 +extern void clear_table (struct table*);
  19 +extern void enregistrer_table (struct table*, double);
  20 +extern bool rechercher_table (struct table*, double);
  21 +extern void imprimer_table (struct table*);
  22 +
... ...
SD/TP6_Hachage/hachage_simple.h.gch 0 → 100644
No preview for this file type
SD/TP6_Hachage/hachage_simple.o 0 → 100644
No preview for this file type
SD/TP6_Hachage/liste_double.c 0 → 100644
... ... @@ -0,0 +1,121 @@
  1 +#include <stdio.h>
  2 +#include <stdlib.h>
  3 +#include <assert.h>
  4 +#include <stdbool.h>
  5 +#include "liste_double.h"
  6 +
  7 +void init_liste_double (struct liste_double* L)
  8 +{
  9 + L->tete = (struct maillon_double*)0;
  10 + L->nbelem = 0;
  11 +}
  12 +
  13 +void ajouter_en_tete_liste_double (struct liste_double* L, double d)
  14 +{ struct maillon_double* nouveau;
  15 +
  16 + nouveau = (struct maillon_double*)malloc (sizeof (struct maillon_double));
  17 + assert (nouveau != (struct maillon_double*)0);
  18 +/* appeler ici un éventuel constructeur pour nouveau->value */
  19 + nouveau->value = d; /* affectation de la valeur */
  20 + nouveau->next = L->tete;
  21 + L->tete = nouveau;
  22 + L->nbelem += 1;
  23 +}
  24 +
  25 +void clear_liste_double (struct liste_double* L)
  26 +{ struct maillon_double* courant;
  27 + struct maillon_double* suivant;
  28 + int i;
  29 +
  30 + courant = L->tete;
  31 + for (i = 0; i < L->nbelem; i++)
  32 + { suivant = courant->next;
  33 +/* appeler ici un éventuel destructeur pour nouveau->value */
  34 + free (courant);
  35 + courant = suivant;
  36 + }
  37 +}
  38 +
  39 +
  40 +bool recherche_liste_double (struct liste_double* L, double d)
  41 +{ struct maillon_double* M;
  42 + int i;
  43 +
  44 + M = L->tete;
  45 + for (i = 0; i < L->nbelem; i++)
  46 + {
  47 + if (M->value == d){
  48 + return true;
  49 + }
  50 + M = M->next;
  51 + }
  52 + return false;
  53 +}
  54 +/*
  55 + * Sous-fonction de set_liste_double.
  56 + * Si L = [m1, m2, ..., mn] avant l'appel alors
  57 + * L = [mn, ..., m2, m1] après l'appel.
  58 + * Aucune allocation dynamique n'est effectuée.
  59 + * Seuls les pointeurs sont modifiés
  60 + */
  61 +
  62 +static void retourner_liste_double (struct liste_double* L)
  63 +{ struct maillon_double *precedent, *courant, *suivant;
  64 + int i;
  65 +
  66 + if (L->nbelem >= 2)
  67 + { courant = L->tete;
  68 + suivant = courant->next;
  69 + courant->next = (struct maillon_double*)0;
  70 + for (i = 1; i < L->nbelem; i++)
  71 + { precedent = courant;
  72 + courant = suivant;
  73 + suivant = suivant->next;
  74 + courant->next = precedent;
  75 + }
  76 + L->tete = courant;
  77 + }
  78 +}
  79 +
  80 +void set_liste_double (struct liste_double* dst, struct liste_double* src)
  81 +{ struct maillon_double* M;
  82 + int i;
  83 +
  84 + if (dst != src)
  85 + { clear_liste_double (dst);
  86 + init_liste_double (dst);
  87 + M = src->tete;
  88 + for (i = 0; i < src->nbelem; i++)
  89 + { ajouter_en_tete_liste_double (dst, M->value);
  90 + M = M->next;
  91 + }
  92 + retourner_liste_double (dst);
  93 + }
  94 +}
  95 +
  96 +void extraire_tete_liste_double (double* d, struct liste_double* L)
  97 +{ struct maillon_double* tete;
  98 +
  99 + assert (L->nbelem != 0);
  100 + tete = L->tete;
  101 + *d = tete->value; /* affectation */
  102 + L->tete = tete->next;
  103 + L->nbelem -= 1;
  104 + free (tete);
  105 +}
  106 +
  107 +void imprimer_liste_double (struct liste_double* L)
  108 +{ struct maillon_double* M;
  109 + int i;
  110 +
  111 + printf ("[");
  112 + M = L->tete;
  113 + for (i = 0; i < L->nbelem; i++)
  114 + { if (i == 0)
  115 + printf ("%f", M->value);
  116 + else
  117 + printf (", %f", M->value);
  118 + M = M->next;
  119 + }
  120 + printf ("]\n");
  121 +}
... ...
SD/TP6_Hachage/liste_double.h 0 → 100644
... ... @@ -0,0 +1,72 @@
  1 +#if ! defined (LISTE_DOUBLE_H)
  2 +#define LISTE_DOUBLE_H 1
  3 +
  4 +/**********************************************************************
  5 + * IMPLANTATION
  6 + *
  7 + * Spécification de l'implantation
  8 + *
  9 + * Implantation des listes simplement chaînées de doubles
  10 + *
  11 + * Les maillons sont alloués dynamiquement.
  12 + * Le champ next du dernier maillon vaut (struct maillon_double*)0
  13 + *
  14 + * Le champ tete d'une liste pointe vers le premier maillon
  15 + * Le champ nbelem est égal au nombre de maillons de la liste
  16 + * La liste vide est codée par (tete, nbelem) = ((struct maillon_double*)0, 0)
  17 + *
  18 + * Des listes distinctes ont des maillons distincts (pas de maillon partagé).
  19 + **********************************************************************/
  20 +
  21 +struct maillon_double
  22 +{ double value;
  23 + struct maillon_double* next;
  24 +};
  25 +
  26 +struct liste_double
  27 +{ struct maillon_double* tete;
  28 + int nbelem;
  29 +};
  30 +
  31 +/**********************************************************************
  32 + * PROTOTYPES DES FONCTIONS (TYPE ABSTRAIT)
  33 + **********************************************************************/
  34 +
  35 +/*
  36 + * Constructeur. Initialise son paramètre à la liste vide
  37 + */
  38 +
  39 +extern void init_liste_double (struct liste_double*);
  40 +
  41 +/*
  42 + * Destructeur
  43 + */
  44 +
  45 +extern void clear_liste_double (struct liste_double*);
  46 +
  47 +/*
  48 + * Affecte une copie de src à dst
  49 + */
  50 +
  51 +extern void set_liste_double
  52 + (struct liste_double* dst, struct liste_double* src);
  53 +
  54 +/*
  55 + * Ajout d'un double en tête de liste
  56 + */
  57 +
  58 +extern void ajouter_en_tete_liste_double (struct liste_double*, double);
  59 +
  60 +/*
  61 + * Affecte à *d la valeur du premier élément de L et supprime cet élément de L.
  62 + * La liste L est supposée non vide.
  63 + */
  64 +
  65 +extern void extraire_tete_liste_double (double* d, struct liste_double* L);
  66 +
  67 +/*
  68 + * Impression.
  69 + */
  70 +
  71 +extern void imprimer_liste_double (struct liste_double*);
  72 +#endif
... ...
SD/TP6_Hachage/liste_double.o 0 → 100644
No preview for this file type
SD/TP6_Hachage/liste_double/Makefile 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +CC=gcc
  2 +CFLAGS=-g -Wall -Wmissing-prototypes
  3 +LDFLAGS=-g
  4 +objects := $(patsubst %.c,%.o,$(wildcard *.c))
  5 +all: main
  6 +clean:
  7 + -rm $(objects)
  8 + -rm main
  9 +main: $(objects)
  10 +# gcc -MM *.c pour obtenir les deux lignes ci-dessous
  11 +liste_double.o: liste_double.c liste_double.h
  12 +main.o: main.c liste_double.h
... ...
SD/TP6_Hachage/liste_double/liste_double.c 0 → 100644
... ... @@ -0,0 +1,105 @@
  1 +#include <stdio.h>
  2 +#include <stdlib.h>
  3 +#include <assert.h>
  4 +#include "liste_double.h"
  5 +
  6 +void init_liste_double (struct liste_double* L)
  7 +{
  8 + L->tete = (struct maillon_double*)0;
  9 + L->nbelem = 0;
  10 +}
  11 +
  12 +void ajouter_en_tete_liste_double (struct liste_double* L, double d)
  13 +{ struct maillon_double* nouveau;
  14 +
  15 + nouveau = (struct maillon_double*)malloc (sizeof (struct maillon_double));
  16 + assert (nouveau != (struct maillon_double*)0);
  17 +/* appeler ici un éventuel constructeur pour nouveau->value */
  18 + nouveau->value = d; /* affectation de la valeur */
  19 + nouveau->next = L->tete;
  20 + L->tete = nouveau;
  21 + L->nbelem += 1;
  22 +}
  23 +
  24 +void clear_liste_double (struct liste_double* L)
  25 +{ struct maillon_double* courant;
  26 + struct maillon_double* suivant;
  27 + int i;
  28 +
  29 + courant = L->tete;
  30 + for (i = 0; i < L->nbelem; i++)
  31 + { suivant = courant->next;
  32 +/* appeler ici un éventuel destructeur pour nouveau->value */
  33 + free (courant);
  34 + courant = suivant;
  35 + }
  36 +}
  37 +
  38 +/*
  39 + * Sous-fonction de set_liste_double.
  40 + * Si L = [m1, m2, ..., mn] avant l'appel alors
  41 + * L = [mn, ..., m2, m1] après l'appel.
  42 + * Aucune allocation dynamique n'est effectuée.
  43 + * Seuls les pointeurs sont modifiés
  44 + */
  45 +
  46 +static void retourner_liste_double (struct liste_double* L)
  47 +{ struct maillon_double *precedent, *courant, *suivant;
  48 + int i;
  49 +
  50 + if (L->nbelem >= 2)
  51 + { courant = L->tete;
  52 + suivant = courant->next;
  53 + courant->next = (struct maillon_double*)0;
  54 + for (i = 1; i < L->nbelem; i++)
  55 + { precedent = courant;
  56 + courant = suivant;
  57 + suivant = suivant->next;
  58 + courant->next = precedent;
  59 + }
  60 + L->tete = courant;
  61 + }
  62 +}
  63 +
  64 +void set_liste_double (struct liste_double* dst, struct liste_double* src)
  65 +{ struct maillon_double* M;
  66 + int i;
  67 +
  68 + if (dst != src)
  69 + { clear_liste_double (dst);
  70 + init_liste_double (dst);
  71 + M = src->tete;
  72 + for (i = 0; i < src->nbelem; i++)
  73 + { ajouter_en_tete_liste_double (dst, M->value);
  74 + M = M->next;
  75 + }
  76 + retourner_liste_double (dst);
  77 + }
  78 +}
  79 +
  80 +void extraire_tete_liste_double (double* d, struct liste_double* L)
  81 +{ struct maillon_double* tete;
  82 +
  83 + assert (L->nbelem != 0);
  84 + tete = L->tete;
  85 + *d = tete->value; /* affectation */
  86 + L->tete = tete->next;
  87 + L->nbelem -= 1;
  88 + free (tete);
  89 +}
  90 +
  91 +void imprimer_liste_double (struct liste_double* L)
  92 +{ struct maillon_double* M;
  93 + int i;
  94 +
  95 + printf ("[");
  96 + M = L->tete;
  97 + for (i = 0; i < L->nbelem; i++)
  98 + { if (i == 0)
  99 + printf ("%f", M->value);
  100 + else
  101 + printf (", %f", M->value);
  102 + M = M->next;
  103 + }
  104 + printf ("]\n");
  105 +}
... ...
SD/TP6_Hachage/liste_double/liste_double.h 0 → 100644
... ... @@ -0,0 +1,72 @@
  1 +#if ! defined (LISTE_DOUBLE_H)
  2 +#define LISTE_DOUBLE_H 1
  3 +
  4 +/**********************************************************************
  5 + * IMPLANTATION
  6 + *
  7 + * Spécification de l'implantation
  8 + *
  9 + * Implantation des listes simplement chaînées de doubles
  10 + *
  11 + * Les maillons sont alloués dynamiquement.
  12 + * Le champ next du dernier maillon vaut (struct maillon_double*)0
  13 + *
  14 + * Le champ tete d'une liste pointe vers le premier maillon
  15 + * Le champ nbelem est égal au nombre de maillons de la liste
  16 + * La liste vide est codée par (tete, nbelem) = ((struct maillon_double*)0, 0)
  17 + *
  18 + * Des listes distinctes ont des maillons distincts (pas de maillon partagé).
  19 + **********************************************************************/
  20 +
  21 +struct maillon_double
  22 +{ double value;
  23 + struct maillon_double* next;
  24 +};
  25 +
  26 +struct liste_double
  27 +{ struct maillon_double* tete;
  28 + int nbelem;
  29 +};
  30 +
  31 +/**********************************************************************
  32 + * PROTOTYPES DES FONCTIONS (TYPE ABSTRAIT)
  33 + **********************************************************************/
  34 +
  35 +/*
  36 + * Constructeur. Initialise son paramètre à la liste vide
  37 + */
  38 +
  39 +extern void init_liste_double (struct liste_double*);
  40 +
  41 +/*
  42 + * Destructeur
  43 + */
  44 +
  45 +extern void clear_liste_double (struct liste_double*);
  46 +
  47 +/*
  48 + * Affecte une copie de src à dst
  49 + */
  50 +
  51 +extern void set_liste_double
  52 + (struct liste_double* dst, struct liste_double* src);
  53 +
  54 +/*
  55 + * Ajout d'un double en tête de liste
  56 + */
  57 +
  58 +extern void ajouter_en_tete_liste_double (struct liste_double*, double);
  59 +
  60 +/*
  61 + * Affecte à *d la valeur du premier élément de L et supprime cet élément de L.
  62 + * La liste L est supposée non vide.
  63 + */
  64 +
  65 +extern void extraire_tete_liste_double (double* d, struct liste_double* L);
  66 +
  67 +/*
  68 + * Impression.
  69 + */
  70 +
  71 +extern void imprimer_liste_double (struct liste_double*);
  72 +#endif
... ...
SD/TP6_Hachage/liste_double/main.c 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +#include "liste_double.h"
  2 +
  3 +int main ()
  4 +{ struct liste_double A;
  5 +
  6 + init_liste_double (&A);
  7 +
  8 + ajouter_en_tete_liste_double (&A, -0.1);
  9 + ajouter_en_tete_liste_double (&A, 0.0);
  10 + ajouter_en_tete_liste_double (&A, 3.14);
  11 +
  12 + imprimer_liste_double (&A);
  13 +
  14 + clear_liste_double (&A);
  15 + return 0;
  16 +}
... ...
SD/TP6_Hachage/main.c 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +/* main.c */
  2 +#include <stdio.h>
  3 +#include "hachage_simple.h"
  4 +
  5 +int hachage_basique (double d)
  6 +{
  7 + return (int)d % N;
  8 +}
  9 +
  10 +int main ()
  11 +{
  12 +
  13 + struct table T;
  14 + double x;
  15 + init_table (&T, &hachage_basique);
  16 + /*scanf ("%lf", &x);
  17 + while (x != -1){
  18 + enregistrer_table (&T, x);
  19 + imprimer_table (&T);
  20 + scanf ("%lf", &x);
  21 + }
  22 + clear_table (&T);*/
  23 + return 0;
  24 +}
... ...
SD/TP6_Hachage/main.o 0 → 100644
No preview for this file type
SD/TP6_Hachage/prog 0 → 100755
No preview for this file type
arbres.tgz 0 → 100644
No preview for this file type