From 5be5d85e429b380d0b0bb5fe8721c6dd1e55e58b Mon Sep 17 00:00:00 2001 From: Vincent Benoist Date: Fri, 14 Jun 2019 14:35:10 +0200 Subject: [PATCH] tp processus --- ProcessusMultiThread/Tp1/Makefile | 17 +++++++++++++++++ ProcessusMultiThread/Tp1/oldversion/tp1_fork.c | 31 +++++++++++++++++++++++++++++++ ProcessusMultiThread/Tp1/oldversion/tp1_fork.o | Bin 0 -> 2200 bytes ProcessusMultiThread/Tp1/prog | Bin 0 -> 8952 bytes ProcessusMultiThread/Tp1/tp1_fork_ex3.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ProcessusMultiThread/Tp1/tp1_fork_ex3.o | Bin 0 -> 3160 bytes ProcessusMultiThread/Tp2/Makefile | 17 +++++++++++++++++ ProcessusMultiThread/Tp2/cmd_suivi | Bin 0 -> 8848 bytes ProcessusMultiThread/Tp2/cmd_suivi.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ ProcessusMultiThread/Tp2/dir.txt | 9 +++++++++ ProcessusMultiThread/Tp2/dir2.txt | 1 + ProcessusMultiThread/Tp2/pd_sm | Bin 0 -> 8952 bytes ProcessusMultiThread/Tp2/pipe | Bin 0 -> 13304 bytes ProcessusMultiThread/Tp2/pipe_lec.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ProcessusMultiThread/Tp2/produit | Bin 0 -> 8800 bytes ProcessusMultiThread/Tp2/produit.c | 11 +++++++++++ ProcessusMultiThread/Tp2/produit_somme.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ProcessusMultiThread/Tp2/prog | Bin 0 -> 8960 bytes ProcessusMultiThread/Tp2/redirect | Bin 0 -> 9096 bytes ProcessusMultiThread/Tp2/redirect.c | 41 +++++++++++++++++++++++++++++++++++++++++ ProcessusMultiThread/Tp2/somme | Bin 0 -> 8800 bytes ProcessusMultiThread/Tp2/somme.c | 11 +++++++++++ ProcessusMultiThread/Tp2/tp2_7 | Bin 0 -> 9048 bytes ProcessusMultiThread/Tp2/tp2_7.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ProcessusMultiThread/Tp2/tp2_dup_pipe.c | 37 +++++++++++++++++++++++++++++++++++++ ProcessusMultiThread/Tp2/tp2_dup_pipe.o | Bin 0 -> 2416 bytes ProcessusMultiThread/ds_2018/ds | Bin 0 -> 14088 bytes ProcessusMultiThread/ds_2018/ds.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ProcessusMultiThread/tp3/data.txt | 3 +++ ProcessusMultiThread/tp3/tpThread.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ProcessusMultiThread/tp3/tpThread2.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ProcessusMultiThread/tp3/tpthread | Bin 0 -> 13624 bytes ProcessusMultiThread/tp3/tpthread2 | Bin 0 -> 13496 bytes SD/TP6_Hachage/V1/Makefile | 17 +++++++++++++++++ SD/TP6_Hachage/V1/a.out | Bin 0 -> 21544 bytes SD/TP6_Hachage/V1/hachage_simple.c | 41 +++++++++++++++++++++++++++++++++++++++++ SD/TP6_Hachage/V1/hachage_simple.h | 22 ++++++++++++++++++++++ SD/TP6_Hachage/V1/hachage_simple.h.gch | Bin 0 -> 1577456 bytes SD/TP6_Hachage/V1/hachage_simple.o | Bin 0 -> 2480 bytes SD/TP6_Hachage/V1/liste_double.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SD/TP6_Hachage/V1/liste_double.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SD/TP6_Hachage/V1/liste_double.h.gch | Bin 0 -> 1565136 bytes SD/TP6_Hachage/V1/liste_double.o | Bin 0 -> 10584 bytes SD/TP6_Hachage/V1/main.c | 24 ++++++++++++++++++++++++ SD/TP6_Hachage/V1/main.o | Bin 0 -> 7384 bytes SD/TP6_Hachage/V1/prog | Bin 0 -> 19440 bytes SD/TP6_Hachage/a.out | Bin 0 -> 21472 bytes SD/TP6_Hachage/abr.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SD/TP6_Hachage/abr.h | 29 +++++++++++++++++++++++++++++ SD/TP6_Hachage/abr.o | Bin 0 -> 11520 bytes SD/TP6_Hachage/hachage_simple.c | 29 +++++++++++++++++------------ SD/TP6_Hachage/hachage_simple.h | 4 ++-- SD/TP6_Hachage/hachage_simple.h.gch | Bin 1569264 -> 0 bytes SD/TP6_Hachage/hachage_simple.o | Bin 2032 -> 0 bytes SD/TP6_Hachage/liste_double.c | 121 ------------------------------------------------------------------------------------------------------------------------- SD/TP6_Hachage/liste_double.h | 72 ------------------------------------------------------------------------ SD/TP6_Hachage/liste_double.o | Bin 4016 -> 0 bytes SD/TP6_Hachage/main.c | 10 +++++----- SD/TP6_Hachage/main.o | Bin 1608 -> 0 bytes SD/TP6_Hachage/prog | Bin 13784 -> 0 bytes 60 files changed, 1295 insertions(+), 212 deletions(-) create mode 100644 ProcessusMultiThread/Tp1/Makefile create mode 100644 ProcessusMultiThread/Tp1/oldversion/tp1_fork.c create mode 100644 ProcessusMultiThread/Tp1/oldversion/tp1_fork.o create mode 100755 ProcessusMultiThread/Tp1/prog create mode 100644 ProcessusMultiThread/Tp1/tp1_fork_ex3.c create mode 100644 ProcessusMultiThread/Tp1/tp1_fork_ex3.o create mode 100644 ProcessusMultiThread/Tp2/Makefile create mode 100755 ProcessusMultiThread/Tp2/cmd_suivi create mode 100644 ProcessusMultiThread/Tp2/cmd_suivi.c create mode 100644 ProcessusMultiThread/Tp2/dir.txt create mode 100644 ProcessusMultiThread/Tp2/dir2.txt create mode 100755 ProcessusMultiThread/Tp2/pd_sm create mode 100755 ProcessusMultiThread/Tp2/pipe create mode 100644 ProcessusMultiThread/Tp2/pipe_lec.c create mode 100755 ProcessusMultiThread/Tp2/produit create mode 100644 ProcessusMultiThread/Tp2/produit.c create mode 100644 ProcessusMultiThread/Tp2/produit_somme.c create mode 100755 ProcessusMultiThread/Tp2/prog create mode 100755 ProcessusMultiThread/Tp2/redirect create mode 100644 ProcessusMultiThread/Tp2/redirect.c create mode 100755 ProcessusMultiThread/Tp2/somme create mode 100644 ProcessusMultiThread/Tp2/somme.c create mode 100755 ProcessusMultiThread/Tp2/tp2_7 create mode 100644 ProcessusMultiThread/Tp2/tp2_7.c create mode 100644 ProcessusMultiThread/Tp2/tp2_dup_pipe.c create mode 100644 ProcessusMultiThread/Tp2/tp2_dup_pipe.o create mode 100755 ProcessusMultiThread/ds_2018/ds create mode 100644 ProcessusMultiThread/ds_2018/ds.c create mode 100644 ProcessusMultiThread/tp3/data.txt create mode 100644 ProcessusMultiThread/tp3/tpThread.c create mode 100644 ProcessusMultiThread/tp3/tpThread2.c create mode 100755 ProcessusMultiThread/tp3/tpthread create mode 100755 ProcessusMultiThread/tp3/tpthread2 create mode 100644 SD/TP6_Hachage/V1/Makefile create mode 100755 SD/TP6_Hachage/V1/a.out create mode 100644 SD/TP6_Hachage/V1/hachage_simple.c create mode 100644 SD/TP6_Hachage/V1/hachage_simple.h create mode 100644 SD/TP6_Hachage/V1/hachage_simple.h.gch create mode 100644 SD/TP6_Hachage/V1/hachage_simple.o create mode 100644 SD/TP6_Hachage/V1/liste_double.c create mode 100644 SD/TP6_Hachage/V1/liste_double.h create mode 100644 SD/TP6_Hachage/V1/liste_double.h.gch create mode 100644 SD/TP6_Hachage/V1/liste_double.o create mode 100644 SD/TP6_Hachage/V1/main.c create mode 100644 SD/TP6_Hachage/V1/main.o create mode 100755 SD/TP6_Hachage/V1/prog create mode 100755 SD/TP6_Hachage/a.out create mode 100644 SD/TP6_Hachage/abr.c create mode 100644 SD/TP6_Hachage/abr.h create mode 100644 SD/TP6_Hachage/abr.o delete mode 100644 SD/TP6_Hachage/liste_double.c delete mode 100644 SD/TP6_Hachage/liste_double.h delete mode 100644 SD/TP6_Hachage/liste_double.o diff --git a/ProcessusMultiThread/Tp1/Makefile b/ProcessusMultiThread/Tp1/Makefile new file mode 100644 index 0000000..a477689 --- /dev/null +++ b/ProcessusMultiThread/Tp1/Makefile @@ -0,0 +1,17 @@ +.PHONY: clean,real-clean +LD = gcc +CC = gcc +CFLAGS = -Wall -W -Werror +SRC=$(wildcard *.c) +OBJ=$(SRC:.c=.o) +prog : $(OBJ) + $(LD) -o $@ $^ + +%.o : %.c + $(CC) $(CFLAGS) -c $^ + +clean : + rm -f *.o + +real-clean : clean + rm -f prog \ No newline at end of file diff --git a/ProcessusMultiThread/Tp1/oldversion/tp1_fork.c b/ProcessusMultiThread/Tp1/oldversion/tp1_fork.c new file mode 100644 index 0000000..1082a39 --- /dev/null +++ b/ProcessusMultiThread/Tp1/oldversion/tp1_fork.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +int main(){ + int cr, cpt=0; + if((cr=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + for(;;){ + if(cr ==0){ + printf("fils"); + sleep(1); + } else { + int r, pid; + printf("pere"); + sleep(2); + cpt++; + if (cpt==5) { + exit(0); + } + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + } + } + return 0; +} diff --git a/ProcessusMultiThread/Tp1/oldversion/tp1_fork.o b/ProcessusMultiThread/Tp1/oldversion/tp1_fork.o new file mode 100644 index 0000000..e95f74d Binary files /dev/null and b/ProcessusMultiThread/Tp1/oldversion/tp1_fork.o differ diff --git a/ProcessusMultiThread/Tp1/prog b/ProcessusMultiThread/Tp1/prog new file mode 100755 index 0000000..da4426f Binary files /dev/null and b/ProcessusMultiThread/Tp1/prog differ diff --git a/ProcessusMultiThread/Tp1/tp1_fork_ex3.c b/ProcessusMultiThread/Tp1/tp1_fork_ex3.c new file mode 100644 index 0000000..3dbbf89 --- /dev/null +++ b/ProcessusMultiThread/Tp1/tp1_fork_ex3.c @@ -0,0 +1,111 @@ +#include +#include +#include +#include +/* +int main(){ + int cr, ent=0; + if((cr=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(cr == 0){ + printf("dans le fils, val de ent : %d\n", ent); + ent ++; + printf("dans le fils, val de ent après incrémentation: %d\n", ent); + } else { + int r, pid; + printf("dans le père, val de ent : %d\n", ent); + ent++; + printf("dans le père, val de ent après incrémentation: %d\n", ent); + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + } + return 0; +} + +int main(){ + int fork1, fork2; + if((fork1=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fork1 == 0){ + printf("dans le fils1, pid: %d\n", getpid()); + sleep(2); + } + + else { + if((fork2=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fork2 == 0){ + printf("dans le fils2, pid: %d\n", getpid()); + sleep(4); + } + else{ + int r, pid; + printf("dans le père, val de ent : %d\n", getpid()); + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + } + } + return 0; +} +*/ +int main(){ + int fils, petitfils; + if((fils=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fils == 0){ + sleep(2); + if((petitfils=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(petitfils == 0){ + sleep(4); + printf("dans le petitfils, pid: %d\n", getpid()); + for(;;){} + exit(8); + } + else{ + int r, pid; + printf("dans le fils, val de ent : %d\n", getpid()); + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + if(WIFEXITED(r)){ + printf("Mort normale du fils: %d\n", WEXITSTATUS(r)); + }else if( WIFSIGNALED(r)){ + printf("Fils mort avec le code: %d\n", WTERMSIG(r)); + } + exit(2); + } + } else { + int r, pid; + printf("dans le père, val de ent : %d\n", getpid()); + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + if(WIFEXITED(r)){ + printf("Mort normale du fils: %d\n", WEXITSTATUS(r)); + }else if( WIFSIGNALED(r)){ + printf("Fils mort avec le code: %d\n", WTERMSIG(r)); + } + } + return 0; +} diff --git a/ProcessusMultiThread/Tp1/tp1_fork_ex3.o b/ProcessusMultiThread/Tp1/tp1_fork_ex3.o new file mode 100644 index 0000000..c725810 Binary files /dev/null and b/ProcessusMultiThread/Tp1/tp1_fork_ex3.o differ diff --git a/ProcessusMultiThread/Tp2/Makefile b/ProcessusMultiThread/Tp2/Makefile new file mode 100644 index 0000000..a477689 --- /dev/null +++ b/ProcessusMultiThread/Tp2/Makefile @@ -0,0 +1,17 @@ +.PHONY: clean,real-clean +LD = gcc +CC = gcc +CFLAGS = -Wall -W -Werror +SRC=$(wildcard *.c) +OBJ=$(SRC:.c=.o) +prog : $(OBJ) + $(LD) -o $@ $^ + +%.o : %.c + $(CC) $(CFLAGS) -c $^ + +clean : + rm -f *.o + +real-clean : clean + rm -f prog \ No newline at end of file diff --git a/ProcessusMultiThread/Tp2/cmd_suivi b/ProcessusMultiThread/Tp2/cmd_suivi new file mode 100755 index 0000000..be03903 Binary files /dev/null and b/ProcessusMultiThread/Tp2/cmd_suivi differ diff --git a/ProcessusMultiThread/Tp2/cmd_suivi.c b/ProcessusMultiThread/Tp2/cmd_suivi.c new file mode 100644 index 0000000..724dacd --- /dev/null +++ b/ProcessusMultiThread/Tp2/cmd_suivi.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +int main(){ + int fork1, fork2, fork3; + if((fork1=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fork1 == 0){ + if(execlp("who","who",NULL)==-1){ + perror("echec execlp"); + exit(1); + } + }else{ + int pid, r; + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + if((fork2=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fork2 == 0){ + if(execlp("ps","ps","-x",NULL)==-1){ + perror("echec execlp"); + exit(1); + } + }else{ + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + if((fork3=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fork3 == 0){ + if(execlp("ls","ls","-la",NULL)==-1){ + perror("echec execlp"); + exit(1); + } + }else{ + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + } + } + } + return 0; +} diff --git a/ProcessusMultiThread/Tp2/dir.txt b/ProcessusMultiThread/Tp2/dir.txt new file mode 100644 index 0000000..7be257e --- /dev/null +++ b/ProcessusMultiThread/Tp2/dir.txt @@ -0,0 +1,9 @@ +-la +-la +-la +-la +-la +-la +-la +-la +-la diff --git a/ProcessusMultiThread/Tp2/dir2.txt b/ProcessusMultiThread/Tp2/dir2.txt new file mode 100644 index 0000000..28cbaa0 --- /dev/null +++ b/ProcessusMultiThread/Tp2/dir2.txt @@ -0,0 +1 @@ +-la diff --git a/ProcessusMultiThread/Tp2/pd_sm b/ProcessusMultiThread/Tp2/pd_sm new file mode 100755 index 0000000..e8f97a6 Binary files /dev/null and b/ProcessusMultiThread/Tp2/pd_sm differ diff --git a/ProcessusMultiThread/Tp2/pipe b/ProcessusMultiThread/Tp2/pipe new file mode 100755 index 0000000..e615734 Binary files /dev/null and b/ProcessusMultiThread/Tp2/pipe differ diff --git a/ProcessusMultiThread/Tp2/pipe_lec.c b/ProcessusMultiThread/Tp2/pipe_lec.c new file mode 100644 index 0000000..7b3a200 --- /dev/null +++ b/ProcessusMultiThread/Tp2/pipe_lec.c @@ -0,0 +1,69 @@ +#include +#include +#include +#include + + +int main(int argc, char * argv[]){ + if(argc != 2){ + return 1; + } + int fils1, fils2; + int entierCourant; + int tube[2]; + if(pipe(tube)<0){ + + perror("erreur pipe"); + exit(1); + } + + if((fils1=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fils1 == 0){ + close(tube[0]); //fils 1 ne lit pas + printf("entiers:\n"); + scanf("%d",&entierCourant); + while(entierCourant != 0){ + if(entierCourant%2==0){ + write(tube[1], &entierCourant, sizeof(int)); + } + scanf("%d",&entierCourant); + } + close(tube[1]); + } + + else { + if((fils2=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fils2 == 0){ + close(tube[1]); //fils 2 n'écrit pas + while(read(tube[0],&entierCourant,sizeof(int))==sizeof(int)){ + if(entierCourant > atoi(argv[1])){ + printf("%d \n",entierCourant); + } + } + close(tube[0]); + } + else{ + int r, pid; + + close(tube[1]); + close(tube[0]); + + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + printf("\nDans le père, traitement fini\n"); + } + } + return 0; +} diff --git a/ProcessusMultiThread/Tp2/produit b/ProcessusMultiThread/Tp2/produit new file mode 100755 index 0000000..81860ea Binary files /dev/null and b/ProcessusMultiThread/Tp2/produit differ diff --git a/ProcessusMultiThread/Tp2/produit.c b/ProcessusMultiThread/Tp2/produit.c new file mode 100644 index 0000000..102ec03 --- /dev/null +++ b/ProcessusMultiThread/Tp2/produit.c @@ -0,0 +1,11 @@ +#include +#include +#include + +int main(int argc, char * argv[]){ + int n1,n2; + n1=atoi(argv[1]); + n2=atoi(argv[2]); + printf("PID : %d, PPID : %d, %d * %d = %d\n", getpid(), getppid(), n1, n2, n1*n2); + return 0; +} diff --git a/ProcessusMultiThread/Tp2/produit_somme.c b/ProcessusMultiThread/Tp2/produit_somme.c new file mode 100644 index 0000000..26559ed --- /dev/null +++ b/ProcessusMultiThread/Tp2/produit_somme.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +int main(int argc, char * argv[]){ + if(argc != 3){ + return 1; + } + int fork1, fork2; + if((fork1=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fork1 == 0){ + if(execlp("./somme","somme",argv[1],argv[2],NULL)==-1){ + perror("echec execlp"); + exit(1); + } + } + + else { + if((fork2=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fork2 == 0){ + sleep(2); + if(execlp("./produit","produit",argv[1],argv[2],NULL)==-1){ + perror("echec execlp"); + exit(1); + } + } + else{ + int r, pid; + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + }else if(pid==fork1){ + printf("Somme effectuée\n"); + }else if(pid==fork2){ + printf("Produit effectuée\n"); + } + + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + }else if(pid==fork1){ + printf("Somme effectuée\n"); + }else if(pid==fork2){ + printf("Produit effectuée\n"); + } + } + } + return 0; +} diff --git a/ProcessusMultiThread/Tp2/prog b/ProcessusMultiThread/Tp2/prog new file mode 100755 index 0000000..79e99b5 Binary files /dev/null and b/ProcessusMultiThread/Tp2/prog differ diff --git a/ProcessusMultiThread/Tp2/redirect b/ProcessusMultiThread/Tp2/redirect new file mode 100755 index 0000000..c681e12 Binary files /dev/null and b/ProcessusMultiThread/Tp2/redirect differ diff --git a/ProcessusMultiThread/Tp2/redirect.c b/ProcessusMultiThread/Tp2/redirect.c new file mode 100644 index 0000000..0aa4823 --- /dev/null +++ b/ProcessusMultiThread/Tp2/redirect.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include + +int main(){ + + int desc; + if((desc=open("dir2.txt",0666))<0){ + if((desc=creat("dir2.txt",0666))==-1){ + perror("creation fichier impossible"); + exit(1); + } + }else { + if(lseek(desc,0,SEEK_END)==-1){ + perror("creation fichier impossible"); + exit(1); + } + } + close(1); + dup(desc); + int fork1; + if((fork1=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fork1 == 0){ + if(execlp("echo","echo","-la",NULL)==-1){ + perror("echec execlp"); + exit(1); + } + }else{ + int pid, r; + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + } + return 0; +} diff --git a/ProcessusMultiThread/Tp2/somme b/ProcessusMultiThread/Tp2/somme new file mode 100755 index 0000000..5a7b633 Binary files /dev/null and b/ProcessusMultiThread/Tp2/somme differ diff --git a/ProcessusMultiThread/Tp2/somme.c b/ProcessusMultiThread/Tp2/somme.c new file mode 100644 index 0000000..ca62d52 --- /dev/null +++ b/ProcessusMultiThread/Tp2/somme.c @@ -0,0 +1,11 @@ +#include +#include +#include + +int main(int argc, char * argv[]){ + int n1,n2; + n1=atoi(argv[1]); + n2=atoi(argv[2]); + printf("PID : %d, PPID : %d, %d + %d = %d\n", getpid(), getppid(), n1, n2, n1+n2); + return 0; +} diff --git a/ProcessusMultiThread/Tp2/tp2_7 b/ProcessusMultiThread/Tp2/tp2_7 new file mode 100755 index 0000000..4f7e5ac Binary files /dev/null and b/ProcessusMultiThread/Tp2/tp2_7 differ diff --git a/ProcessusMultiThread/Tp2/tp2_7.c b/ProcessusMultiThread/Tp2/tp2_7.c new file mode 100644 index 0000000..3394531 --- /dev/null +++ b/ProcessusMultiThread/Tp2/tp2_7.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + + +int main(int argc, char * argv[]){ + int fils1, fils2; + int tube[2]; + if(pipe(tube)<0){ + perror("erreur pipe"); + exit(1); + } + + if((fils1=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fils1 == 0){ + close(tube[0]); //fils 1 ne lit pas + dup2(tube[1],1); + if(execlp("cat","cat","/etc/passwd",NULL)==-1){ + perror("echec execlp"); + exit(1); + } + } else { + if((fils2=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fils2 == 0){ + close(tube[1]); //fils 2 n'écrit pas + dup2(tube[0],0); + if(execlp("wc","ws",NULL)==-1){ + perror("echec execlp"); + exit(1); + } + + } else{ + int r, pid; + + close(tube[1]); + close(tube[0]); + + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + printf("\nDans le père, traitement fini\n"); + } + } + return 0; +} diff --git a/ProcessusMultiThread/Tp2/tp2_dup_pipe.c b/ProcessusMultiThread/Tp2/tp2_dup_pipe.c new file mode 100644 index 0000000..396ff80 --- /dev/null +++ b/ProcessusMultiThread/Tp2/tp2_dup_pipe.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +/*int main(){ + printf("lancement de la commande ls\n"); + if(execlp("ls","ls","-l",NULL)==-1){ + perror("echec execlp"); + exit(1); + } + return 0; +}*/ + +int main(){ + int fils; + char fich[256]; + printf("nom du fichier ?\n"); + scanf("%s",fich); + if((fils=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fils == 0){ + if(execlp("wc","ws","-l",fich,NULL)==-1){ + perror("echec execlp"); + exit(1); + } + } else { + int r, pid; + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + } + return 0; +} diff --git a/ProcessusMultiThread/Tp2/tp2_dup_pipe.o b/ProcessusMultiThread/Tp2/tp2_dup_pipe.o new file mode 100644 index 0000000..17a2b60 Binary files /dev/null and b/ProcessusMultiThread/Tp2/tp2_dup_pipe.o differ diff --git a/ProcessusMultiThread/ds_2018/ds b/ProcessusMultiThread/ds_2018/ds new file mode 100755 index 0000000..8acbb1b Binary files /dev/null and b/ProcessusMultiThread/ds_2018/ds differ diff --git a/ProcessusMultiThread/ds_2018/ds.c b/ProcessusMultiThread/ds_2018/ds.c new file mode 100644 index 0000000..39e716e --- /dev/null +++ b/ProcessusMultiThread/ds_2018/ds.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include +#include + + +#define ATTENTE 3 +int vitesse_train =0; +int conducteur_actif =1; +pthread_mutex_t mutex; + +void hand(int sig){ + printf("Veuiller bouger\n"); +} + +void * conducteur_action(void* arg){ + while(1){ + sleep(ATTENTE); + pthread_mutex_lock(&mutex); + if(conducteur_actif==0){ + kill(getppid(),SIGINT); + sleep(3); + if(conducteur_actif==0){ + kill(getppid(),SIGKILL); + } + } + conducteur_actif=0; + pthread_mutex_unlock(&mutex); + } +} + +int main(int argc, char * argv[]){ + int fils1; + int action_courante=0; + int tube[2]; + pthread_mutex_init(&mutex,NULL); + if(pipe(tube)<0){ + perror("erreur pipe"); + exit(1); + } + + if((fils1=fork())<0){ + perror("erreur exec du fork"); + exit(1); + } + if(fils1 == 0){ + close(tube[1]); //fils n'écrit pas + int variation_v; + + pthread_t tid1; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create(&tid1, &attr, conducteur_action, NULL); + while(read(tube[0],&variation_v,sizeof(int))==sizeof(int)){ + + pthread_mutex_lock(&mutex); + conducteur_actif = 1; + pthread_mutex_unlock(&mutex); + + vitesse_train = vitesse_train + variation_v; + printf("Vitesse actuelle: %d\n",vitesse_train); + } + close(tube[0]); + } else { + + struct sigaction action; + sigset_t ens; + sigemptyset(&ens); + action.sa_handler = hand; + action.sa_mask =ens; + action.sa_flags = SA_RESTART; + sigaction(SIGINT,&action,NULL); + + close(tube[0]); //pere 1 ne lit pas + printf("Action:\n"); + + scanf("%d",&action_courante); + while(action_courante != -2){ + if((action_courante<2) && (action_courante>-2)){ + write(tube[1], &action_courante, sizeof(int)); + } + scanf("%d",&action_courante); + } + vitesse_train=0; + close(tube[1]); + + int r, pid; + if((pid= wait(&r)) <0){ + perror("erreur exec du wait"); + exit(1); + } + printf("\nDans le père, train arrêté, vitesse: %d\n",vitesse_train); + + } + return 0; +} diff --git a/ProcessusMultiThread/tp3/data.txt b/ProcessusMultiThread/tp3/data.txt new file mode 100644 index 0000000..c0d18e8 --- /dev/null +++ b/ProcessusMultiThread/tp3/data.txt @@ -0,0 +1,3 @@ +1000 0 30 40 50 60 70 80 90 100 +90 +10 diff --git a/ProcessusMultiThread/tp3/tpThread.c b/ProcessusMultiThread/tp3/tpThread.c new file mode 100644 index 0000000..88d1350 --- /dev/null +++ b/ProcessusMultiThread/tp3/tpThread.c @@ -0,0 +1,84 @@ +#include +#include +#include +#define MAX 10 + +int tab[MAX]; +int nb=0; +pthread_mutex_t mutex; + +void lire() { + int i; + printf("saisir %d entiers\n", MAX); + for (i=0; iseuil) nb++; + printf("fin de fonction supSeuil : nb = %d\n", nb); + pthread_mutex_unlock(&mutex); +} +void * infSeuil(void* arg){ + int i; + int seuil =*(int*)arg; + pthread_mutex_lock(&mutex); + for (i=0; i*max) *max=tab[i]; + } +} + +int main(){ + int seuilInf, seuilSup, min, max; + pthread_t tid1, tid2, tid3; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + + pthread_mutex_init(&mutex,NULL); + + + lire(); + affiche(); + + pthread_create(&tid1, &attr, moyenne, NULL); + + + + printf("saisir les seuils sup et inf : "); + scanf("%d%d", &seuilSup, &seuilInf); + int * p_seuilInf = (int *) malloc(sizeof(int)); + *p_seuilInf = seuilInf; + int * p_seuilSupp = (int *) malloc(sizeof(int)); + *p_seuilSupp = seuilSup; + pthread_create(&tid2, &attr, supSeuil,(void *) p_seuilSupp); + pthread_create(&tid3, &attr, infSeuil,(void *) p_seuilInf); + + minMax(&min, &max); + printf("min = %d, max = %d\n", min, max); + pthread_exit(NULL); + return(0); +} diff --git a/ProcessusMultiThread/tp3/tpThread2.c b/ProcessusMultiThread/tp3/tpThread2.c new file mode 100644 index 0000000..ccd6c90 --- /dev/null +++ b/ProcessusMultiThread/tp3/tpThread2.c @@ -0,0 +1,96 @@ +#include +#include +#include +#define MAX 10 + +int tab[MAX]; +int nb=0; +pthread_mutex_t mutex; +struct minMax { + int *min; + int *max; + }; + +void lire() { + int i; + printf("saisir %d entiers\n", MAX); + for (i=0; iseuil){ + pthread_mutex_lock(&mutex); + nb++; + pthread_mutex_unlock(&mutex); + } + } + +} +void * infSeuil(void* arg){ + int i; + int seuil =*(int*)arg; + + for (i=0; i*str_minMax.max) *str_minMax.max=tab[i]; + } +} + +int main(){ + int seuilInf, seuilSup, min, max; + pthread_t tid1, tid2, tid3, tid4; + + pthread_mutex_init(&mutex,NULL); + + lire(); + affiche(); + + pthread_create(&tid1, NULL, moyenne, NULL); + + printf("saisir les seuils sup et inf : "); + scanf("%d%d", &seuilSup, &seuilInf); + + pthread_join(tid1,NULL); + pthread_create(&tid2, NULL, supSeuil,(void *) &seuilSup); + pthread_create(&tid3, NULL, infSeuil,(void *) &seuilInf); + pthread_join(tid2,NULL); + pthread_join(tid3,NULL); + + struct minMax str_minMax; + + str_minMax.min = &min; + str_minMax.max = &max; + pthread_create(&tid4, NULL, minMax,(void *) &str_minMax); + + pthread_join(tid4,NULL); + printf("min = %d, max = %d\nnb=%d", *str_minMax.min, *str_minMax.max, nb); + pthread_exit(NULL); + return(0); +} diff --git a/ProcessusMultiThread/tp3/tpthread b/ProcessusMultiThread/tp3/tpthread new file mode 100755 index 0000000..1087f70 Binary files /dev/null and b/ProcessusMultiThread/tp3/tpthread differ diff --git a/ProcessusMultiThread/tp3/tpthread2 b/ProcessusMultiThread/tp3/tpthread2 new file mode 100755 index 0000000..601563c Binary files /dev/null and b/ProcessusMultiThread/tp3/tpthread2 differ diff --git a/SD/TP6_Hachage/V1/Makefile b/SD/TP6_Hachage/V1/Makefile new file mode 100644 index 0000000..8c97a3a --- /dev/null +++ b/SD/TP6_Hachage/V1/Makefile @@ -0,0 +1,17 @@ +.PHONY: clean,real-clean +LD = gcc +CC = gcc +CFLAGS = +SRC=$(wildcard *.c) +OBJ=$(SRC:.c=.o) +prog : $(OBJ) + $(LD) -o $@ $^ + +%.o : %.c + $(CC) $(CFLAGS) -c $^ + +clean : + rm -f *.o + +real-clean : clean + rm -f prog diff --git a/SD/TP6_Hachage/V1/a.out b/SD/TP6_Hachage/V1/a.out new file mode 100755 index 0000000..54e02da Binary files /dev/null and b/SD/TP6_Hachage/V1/a.out differ diff --git a/SD/TP6_Hachage/V1/hachage_simple.c b/SD/TP6_Hachage/V1/hachage_simple.c new file mode 100644 index 0000000..1445614 --- /dev/null +++ b/SD/TP6_Hachage/V1/hachage_simple.c @@ -0,0 +1,41 @@ +#include "hachage_simple.h" +#include "liste_double.h" +#include +#include +#include +#include + +void init_table (struct table* T, fonction_hachage* H){ + /* int i = 0; + for(i=0; itab[i].L); + } + T->hash = H;*/ +} + +void clear_table (struct table* T){ + /*int i = 0; + for(i=0; itab[i].L); + }*/ +} + +void enregistrer_table (struct table* T, double d){ + /* int i; + i=T->hash(d); + ajouter_en_tete_liste_double(&T->tab[i].L,d);*/ +} + +bool rechercher_table (struct table* T, double d){ + /*int i; + i= T->hash(d); + recherche_liste_double(&T->tab[i].L,d);*/ +} + +void imprimer_table (struct table* T){ + /*int i = 0; + for(i=0; itab[i].L); + } */ +} + diff --git a/SD/TP6_Hachage/V1/hachage_simple.h b/SD/TP6_Hachage/V1/hachage_simple.h new file mode 100644 index 0000000..1820e98 --- /dev/null +++ b/SD/TP6_Hachage/V1/hachage_simple.h @@ -0,0 +1,22 @@ +/* hachage_simple.h */ +#include "liste_double.h" +#include + +struct alveole { + struct liste_double L; +}; + +typedef int fonction_hachage (double); + +#define N 10 +struct table { + struct alveole tab [N]; + fonction_hachage* hash; +}; + +extern void init_table (struct table*, fonction_hachage*); +extern void clear_table (struct table*); +extern void enregistrer_table (struct table*, double); +extern bool rechercher_table (struct table*, double); +extern void imprimer_table (struct table*); + diff --git a/SD/TP6_Hachage/V1/hachage_simple.h.gch b/SD/TP6_Hachage/V1/hachage_simple.h.gch new file mode 100644 index 0000000..68ca226 Binary files /dev/null and b/SD/TP6_Hachage/V1/hachage_simple.h.gch differ diff --git a/SD/TP6_Hachage/V1/hachage_simple.o b/SD/TP6_Hachage/V1/hachage_simple.o new file mode 100644 index 0000000..9cb7728 Binary files /dev/null and b/SD/TP6_Hachage/V1/hachage_simple.o differ diff --git a/SD/TP6_Hachage/V1/liste_double.c b/SD/TP6_Hachage/V1/liste_double.c new file mode 100644 index 0000000..6a140c5 --- /dev/null +++ b/SD/TP6_Hachage/V1/liste_double.c @@ -0,0 +1,121 @@ +#include +#include +#include +#include +#include "liste_double.h" + +void init_liste_double (struct liste_double* L) +{ + L->tete = (struct maillon_double*)0; + L->nbelem = 0; +} + +void ajouter_en_tete_liste_double (struct liste_double* L, double d) +{ struct maillon_double* nouveau; + + nouveau = (struct maillon_double*)malloc (sizeof (struct maillon_double)); + assert (nouveau != (struct maillon_double*)0); +/* appeler ici un éventuel constructeur pour nouveau->value */ + nouveau->value = d; /* affectation de la valeur */ + nouveau->next = L->tete; + L->tete = nouveau; + L->nbelem += 1; +} + +void clear_liste_double (struct liste_double* L) +{ struct maillon_double* courant; + struct maillon_double* suivant; + int i; + + courant = L->tete; + for (i = 0; i < L->nbelem; i++) + { suivant = courant->next; +/* appeler ici un éventuel destructeur pour nouveau->value */ + free (courant); + courant = suivant; + } +} + + +bool recherche_liste_double (struct liste_double* L, double d) +{ struct maillon_double* M; + int i; + + M = L->tete; + for (i = 0; i < L->nbelem; i++) + { + if (M->value == d){ + return true; + } + M = M->next; + } + return false; +} +/* + * Sous-fonction de set_liste_double. + * Si L = [m1, m2, ..., mn] avant l'appel alors + * L = [mn, ..., m2, m1] après l'appel. + * Aucune allocation dynamique n'est effectuée. + * Seuls les pointeurs sont modifiés + */ + +static void retourner_liste_double (struct liste_double* L) +{ struct maillon_double *precedent, *courant, *suivant; + int i; + + if (L->nbelem >= 2) + { courant = L->tete; + suivant = courant->next; + courant->next = (struct maillon_double*)0; + for (i = 1; i < L->nbelem; i++) + { precedent = courant; + courant = suivant; + suivant = suivant->next; + courant->next = precedent; + } + L->tete = courant; + } +} + +void set_liste_double (struct liste_double* dst, struct liste_double* src) +{ struct maillon_double* M; + int i; + + if (dst != src) + { clear_liste_double (dst); + init_liste_double (dst); + M = src->tete; + for (i = 0; i < src->nbelem; i++) + { ajouter_en_tete_liste_double (dst, M->value); + M = M->next; + } + retourner_liste_double (dst); + } +} + +void extraire_tete_liste_double (double* d, struct liste_double* L) +{ struct maillon_double* tete; + + assert (L->nbelem != 0); + tete = L->tete; + *d = tete->value; /* affectation */ + L->tete = tete->next; + L->nbelem -= 1; + free (tete); +} + +void imprimer_liste_double (struct liste_double* L) +{ struct maillon_double* M; + int i; + + printf ("["); + M = L->tete; + for (i = 0; i < L->nbelem; i++) + { if (i == 0) + printf ("%f", M->value); + else + printf (", %f", M->value); + M = M->next; + } + printf ("]\n"); +} diff --git a/SD/TP6_Hachage/V1/liste_double.h b/SD/TP6_Hachage/V1/liste_double.h new file mode 100644 index 0000000..ac8bf74 --- /dev/null +++ b/SD/TP6_Hachage/V1/liste_double.h @@ -0,0 +1,76 @@ +#if ! defined (LISTE_DOUBLE_H) +#define LISTE_DOUBLE_H 1 + +#include + +/********************************************************************** + * IMPLANTATION + * + * Spécification de l'implantation + * + * Implantation des listes simplement chaînées de doubles + * + * Les maillons sont alloués dynamiquement. + * Le champ next du dernier maillon vaut (struct maillon_double*)0 + * + * Le champ tete d'une liste pointe vers le premier maillon + * Le champ nbelem est égal au nombre de maillons de la liste + * La liste vide est codée par (tete, nbelem) = ((struct maillon_double*)0, 0) + * + * Des listes distinctes ont des maillons distincts (pas de maillon partagé). + **********************************************************************/ + +struct maillon_double +{ double value; + struct maillon_double* next; +}; + +struct liste_double +{ struct maillon_double* tete; + int nbelem; +}; + +/********************************************************************** + * PROTOTYPES DES FONCTIONS (TYPE ABSTRAIT) + **********************************************************************/ + +/* + * Constructeur. Initialise son paramètre à la liste vide + */ + +extern void init_liste_double (struct liste_double*); + + +extern bool recherche_liste_double (struct liste_double* , double ); +/* + * Destructeur + */ + +extern void clear_liste_double (struct liste_double*); + +/* + * Affecte une copie de src à dst + */ + +extern void set_liste_double + (struct liste_double* dst, struct liste_double* src); + +/* + * Ajout d'un double en tête de liste + */ + +extern void ajouter_en_tete_liste_double (struct liste_double*, double); + +/* + * Affecte à *d la valeur du premier élément de L et supprime cet élément de L. + * La liste L est supposée non vide. + */ + +extern void extraire_tete_liste_double (double* d, struct liste_double* L); + +/* + * Impression. + */ + +extern void imprimer_liste_double (struct liste_double*); +#endif diff --git a/SD/TP6_Hachage/V1/liste_double.h.gch b/SD/TP6_Hachage/V1/liste_double.h.gch new file mode 100644 index 0000000..8fe9d3d Binary files /dev/null and b/SD/TP6_Hachage/V1/liste_double.h.gch differ diff --git a/SD/TP6_Hachage/V1/liste_double.o b/SD/TP6_Hachage/V1/liste_double.o new file mode 100644 index 0000000..6237e6f Binary files /dev/null and b/SD/TP6_Hachage/V1/liste_double.o differ diff --git a/SD/TP6_Hachage/V1/main.c b/SD/TP6_Hachage/V1/main.c new file mode 100644 index 0000000..571f58b --- /dev/null +++ b/SD/TP6_Hachage/V1/main.c @@ -0,0 +1,24 @@ +/* main.c */ +#include +#include "hachage_simple.h" + +int hachage_basique (double d) +{ + return (int)d % N; +} + +int main () +{ + struct table T; + double x; + init_table (&T, &hachage_basique); + + scanf ("%lf", &x); + while (x != -1){ + enregistrer_table (&T, x); + imprimer_table (&T); + scanf ("%lf", &x); + } + clear_table (&T); + return 0; +} diff --git a/SD/TP6_Hachage/V1/main.o b/SD/TP6_Hachage/V1/main.o new file mode 100644 index 0000000..e7cbeae Binary files /dev/null and b/SD/TP6_Hachage/V1/main.o differ diff --git a/SD/TP6_Hachage/V1/prog b/SD/TP6_Hachage/V1/prog new file mode 100755 index 0000000..9d3d567 Binary files /dev/null and b/SD/TP6_Hachage/V1/prog differ diff --git a/SD/TP6_Hachage/a.out b/SD/TP6_Hachage/a.out new file mode 100755 index 0000000..04854d6 Binary files /dev/null and b/SD/TP6_Hachage/a.out differ diff --git a/SD/TP6_Hachage/abr.c b/SD/TP6_Hachage/abr.c new file mode 100644 index 0000000..80f1bf6 --- /dev/null +++ b/SD/TP6_Hachage/abr.c @@ -0,0 +1,136 @@ +#include +#include +#include +#include "abr.h" + + +static struct abr* new_feuille (int x){ + + struct abr* F; + + F = (struct abr*)malloc (sizeof (struct abr)); + F->gauche = NIL; + F->valeur = x; + F->droit = NIL; + return F; +} + + +struct abr* ajout_abr_rec (int x, struct abr* A){ + if (A == NIL) + return new_feuille (x); + else if (x < A->valeur) + A->gauche = ajout_abr_rec (x, A->gauche); + else + A->droit = ajout_abr_rec (x, A->droit); + return A; +} + +int max( int a, int b){ + + if(a>b){ + return a; + } + return b; +} + +int hauteur_abr( struct abr* A){ + + if(A == NIL){ + return -1; + } + return max(hauteur_abr(A->gauche),hauteur_abr(A->droit))+1; + +} + + +bool recherche_abr_rec (int x, struct abr* A){ + bool b = false; + if (A == NIL){ + return b; + } else if ( x == A->valeur ){ + return true; + } else if (x < A->valeur){ + b=recherche_abr_rec (x, A->gauche); + } else{ + b=recherche_abr_rec (x, A->droit); + } + return b; +} + + +static void affiche_abr (struct abr* A){ + if( A!= NIL){ + affiche_abr(A->gauche); + printf("- %d ", A-> valeur); + affiche_abr(A->droit); + } + +} + + +void imprime_abr (struct abr* A){ + printf("Valeurs de l'arbre: \n"); + affiche_abr(A); + printf(" -\n"); +} + + +static void affiche_abrV2 (struct abr* A, int profondeur){ + if( A!= NIL){ + int i = 0; + for(i=0; i<=profondeur; i++){ + printf("\t"); + } + + printf("%d\n ", A-> valeur); + affiche_abrV2(A->droit, profondeur+1); + affiche_abrV2(A->gauche, profondeur+1); + } + +} + +void imprime_abrV2 (struct abr* A){ + printf("Valeurs de l'arbre: \n"); + affiche_abrV2(A, 0); + printf("\n"); +} + +void clear_abr (struct abr* A) +{ + if (A != NIL) + { clear_abr (A->gauche); + clear_abr (A->droit); + free (A); + } +} + +void imprimeArbreDot( struct abr* A, FILE* f){ + if(A->gauche != NIL){ + fprintf(f,"%d -> %d [label=\"gauche\"];\n", A->valeur, A->gauche->valeur); + imprimeArbreDot(A->gauche,f); + } + if(A->droit != NIL){ + fprintf(f,"%d -> %d [label=\"droit\"];\n", A->valeur, A->droit->valeur); + imprimeArbreDot(A->droit,f); + } +} + + +void imprimeDot( struct abr* A){ + FILE* f; + f = fopen("ABR.dot", "w"); + fprintf(f,"digraph G {\n"); + if(A==NIL){ + fprintf(f,"NIL\n"); + }else if (A->gauche == NIL && A->droit == NIL){ + fprintf(f,"%d\n", A->valeur); + }else { + imprimeArbreDot(A,f); + } + fprintf(f,"}\n"); + fclose(f); + system("dot -Tpdf ABR.dot -GRANKDIR=LR -o ABR.pdf"); + system("evince ABR.pdf &"); +} + diff --git a/SD/TP6_Hachage/abr.h b/SD/TP6_Hachage/abr.h new file mode 100644 index 0000000..6baecd0 --- /dev/null +++ b/SD/TP6_Hachage/abr.h @@ -0,0 +1,29 @@ +#if ! defined (ABR_H) +#define ABR_H 1 + + +#include + +struct abr { + struct abr* gauche; + int valeur; + struct abr* droit; +}; + +#define NIL (struct abr*)0 + + +extern struct abr* ajout_abr_rec (int, struct abr*); + +/* Calcule la hauteur d'un abr*/ +extern int hauteur_abr( struct abr*); + +extern bool recherche_abr_rec (int, struct abr*); + +extern void imprime_abr (struct abr*); + +extern void imprime_abrV2 (struct abr*); + +extern void clear_abr (struct abr*); + +#endif diff --git a/SD/TP6_Hachage/abr.o b/SD/TP6_Hachage/abr.o new file mode 100644 index 0000000..1e124b6 Binary files /dev/null and b/SD/TP6_Hachage/abr.o differ diff --git a/SD/TP6_Hachage/hachage_simple.c b/SD/TP6_Hachage/hachage_simple.c index 5b2851d..7921cf1 100644 --- a/SD/TP6_Hachage/hachage_simple.c +++ b/SD/TP6_Hachage/hachage_simple.c @@ -1,37 +1,42 @@ -#include "hachage_simple.h" -#include "liste_double.h" #include #include #include #include - +#include "hachage_simple.h" +#include "abr.h" void init_table (struct table* T, fonction_hachage* H){ - int i = 0; + int i = 0; for(i=0; itab[N].L); + (T->tab[i].L) = NIL; } + T->hash = H; } void clear_table (struct table* T){ - int i = 0; + int i = 0; for(i=0; itab[N].L); + clear_abr(T->tab[i].L); } - - } void enregistrer_table (struct table* T, double d){ - + int i; + i=T->hash(d); + T->tab[i].L = ajout_abr_rec(i, T->tab[i].L); } bool rechercher_table (struct table* T, double d){ - return true; + int i; + i= T->hash(d); + recherche_abr_rec(i,T->tab[i].L); } void imprimer_table (struct table* T){ - + int i = 0; + for(i=0; itab[i].L); + } } diff --git a/SD/TP6_Hachage/hachage_simple.h b/SD/TP6_Hachage/hachage_simple.h index 1820e98..f5e4d6a 100644 --- a/SD/TP6_Hachage/hachage_simple.h +++ b/SD/TP6_Hachage/hachage_simple.h @@ -1,9 +1,9 @@ /* hachage_simple.h */ -#include "liste_double.h" +#include "abr.h" #include struct alveole { - struct liste_double L; + struct abr* L; }; typedef int fonction_hachage (double); diff --git a/SD/TP6_Hachage/hachage_simple.h.gch b/SD/TP6_Hachage/hachage_simple.h.gch index a1e6bbc..68ca226 100644 Binary files a/SD/TP6_Hachage/hachage_simple.h.gch and b/SD/TP6_Hachage/hachage_simple.h.gch differ diff --git a/SD/TP6_Hachage/hachage_simple.o b/SD/TP6_Hachage/hachage_simple.o index 68ed7f0..448af7b 100644 Binary files a/SD/TP6_Hachage/hachage_simple.o and b/SD/TP6_Hachage/hachage_simple.o differ diff --git a/SD/TP6_Hachage/liste_double.c b/SD/TP6_Hachage/liste_double.c deleted file mode 100644 index 6a140c5..0000000 --- a/SD/TP6_Hachage/liste_double.c +++ /dev/null @@ -1,121 +0,0 @@ -#include -#include -#include -#include -#include "liste_double.h" - -void init_liste_double (struct liste_double* L) -{ - L->tete = (struct maillon_double*)0; - L->nbelem = 0; -} - -void ajouter_en_tete_liste_double (struct liste_double* L, double d) -{ struct maillon_double* nouveau; - - nouveau = (struct maillon_double*)malloc (sizeof (struct maillon_double)); - assert (nouveau != (struct maillon_double*)0); -/* appeler ici un éventuel constructeur pour nouveau->value */ - nouveau->value = d; /* affectation de la valeur */ - nouveau->next = L->tete; - L->tete = nouveau; - L->nbelem += 1; -} - -void clear_liste_double (struct liste_double* L) -{ struct maillon_double* courant; - struct maillon_double* suivant; - int i; - - courant = L->tete; - for (i = 0; i < L->nbelem; i++) - { suivant = courant->next; -/* appeler ici un éventuel destructeur pour nouveau->value */ - free (courant); - courant = suivant; - } -} - - -bool recherche_liste_double (struct liste_double* L, double d) -{ struct maillon_double* M; - int i; - - M = L->tete; - for (i = 0; i < L->nbelem; i++) - { - if (M->value == d){ - return true; - } - M = M->next; - } - return false; -} -/* - * Sous-fonction de set_liste_double. - * Si L = [m1, m2, ..., mn] avant l'appel alors - * L = [mn, ..., m2, m1] après l'appel. - * Aucune allocation dynamique n'est effectuée. - * Seuls les pointeurs sont modifiés - */ - -static void retourner_liste_double (struct liste_double* L) -{ struct maillon_double *precedent, *courant, *suivant; - int i; - - if (L->nbelem >= 2) - { courant = L->tete; - suivant = courant->next; - courant->next = (struct maillon_double*)0; - for (i = 1; i < L->nbelem; i++) - { precedent = courant; - courant = suivant; - suivant = suivant->next; - courant->next = precedent; - } - L->tete = courant; - } -} - -void set_liste_double (struct liste_double* dst, struct liste_double* src) -{ struct maillon_double* M; - int i; - - if (dst != src) - { clear_liste_double (dst); - init_liste_double (dst); - M = src->tete; - for (i = 0; i < src->nbelem; i++) - { ajouter_en_tete_liste_double (dst, M->value); - M = M->next; - } - retourner_liste_double (dst); - } -} - -void extraire_tete_liste_double (double* d, struct liste_double* L) -{ struct maillon_double* tete; - - assert (L->nbelem != 0); - tete = L->tete; - *d = tete->value; /* affectation */ - L->tete = tete->next; - L->nbelem -= 1; - free (tete); -} - -void imprimer_liste_double (struct liste_double* L) -{ struct maillon_double* M; - int i; - - printf ("["); - M = L->tete; - for (i = 0; i < L->nbelem; i++) - { if (i == 0) - printf ("%f", M->value); - else - printf (", %f", M->value); - M = M->next; - } - printf ("]\n"); -} diff --git a/SD/TP6_Hachage/liste_double.h b/SD/TP6_Hachage/liste_double.h deleted file mode 100644 index 469c932..0000000 --- a/SD/TP6_Hachage/liste_double.h +++ /dev/null @@ -1,72 +0,0 @@ -#if ! defined (LISTE_DOUBLE_H) -#define LISTE_DOUBLE_H 1 - -/********************************************************************** - * IMPLANTATION - * - * Spécification de l'implantation - * - * Implantation des listes simplement chaînées de doubles - * - * Les maillons sont alloués dynamiquement. - * Le champ next du dernier maillon vaut (struct maillon_double*)0 - * - * Le champ tete d'une liste pointe vers le premier maillon - * Le champ nbelem est égal au nombre de maillons de la liste - * La liste vide est codée par (tete, nbelem) = ((struct maillon_double*)0, 0) - * - * Des listes distinctes ont des maillons distincts (pas de maillon partagé). - **********************************************************************/ - -struct maillon_double -{ double value; - struct maillon_double* next; -}; - -struct liste_double -{ struct maillon_double* tete; - int nbelem; -}; - -/********************************************************************** - * PROTOTYPES DES FONCTIONS (TYPE ABSTRAIT) - **********************************************************************/ - -/* - * Constructeur. Initialise son paramètre à la liste vide - */ - -extern void init_liste_double (struct liste_double*); - -/* - * Destructeur - */ - -extern void clear_liste_double (struct liste_double*); - -/* - * Affecte une copie de src à dst - */ - -extern void set_liste_double - (struct liste_double* dst, struct liste_double* src); - -/* - * Ajout d'un double en tête de liste - */ - -extern void ajouter_en_tete_liste_double (struct liste_double*, double); - -/* - * Affecte à *d la valeur du premier élément de L et supprime cet élément de L. - * La liste L est supposée non vide. - */ - -extern void extraire_tete_liste_double (double* d, struct liste_double* L); - -/* - * Impression. - */ - -extern void imprimer_liste_double (struct liste_double*); -#endif diff --git a/SD/TP6_Hachage/liste_double.o b/SD/TP6_Hachage/liste_double.o deleted file mode 100644 index 1daa129..0000000 Binary files a/SD/TP6_Hachage/liste_double.o and /dev/null differ diff --git a/SD/TP6_Hachage/main.c b/SD/TP6_Hachage/main.c index 7281dd9..571f58b 100644 --- a/SD/TP6_Hachage/main.c +++ b/SD/TP6_Hachage/main.c @@ -9,16 +9,16 @@ int hachage_basique (double d) int main () { - struct table T; double x; init_table (&T, &hachage_basique); - /*scanf ("%lf", &x); + + scanf ("%lf", &x); while (x != -1){ enregistrer_table (&T, x); - imprimer_table (&T); - scanf ("%lf", &x); + imprimer_table (&T); + scanf ("%lf", &x); } - clear_table (&T);*/ + clear_table (&T); return 0; } diff --git a/SD/TP6_Hachage/main.o b/SD/TP6_Hachage/main.o index 3962819..095d9ed 100644 Binary files a/SD/TP6_Hachage/main.o and b/SD/TP6_Hachage/main.o differ diff --git a/SD/TP6_Hachage/prog b/SD/TP6_Hachage/prog index e157c2f..04854d6 100755 Binary files a/SD/TP6_Hachage/prog and b/SD/TP6_Hachage/prog differ -- libgit2 0.21.2