From: Jérôme Benoit Date: Tue, 7 Mar 2017 08:57:28 +0000 (+0100) Subject: Add TP5 skeleton X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=16d1d589590215264ffec1c7af6fee2af81fb351;p=Algorithmic_C.git Add TP5 skeleton Signed-off-by: Jérôme Benoit --- diff --git a/TP5/exo1/Makefile b/TP5/exo1/Makefile new file mode 100644 index 0000000..339be0c --- /dev/null +++ b/TP5/exo1/Makefile @@ -0,0 +1,79 @@ +# Sample Makefile to build simple project. +# +# This Makefile expect all source files (.c) to be at the same level, in the +# current working directory. +# +# It will automatically generate dependencies, compile all files, and produce a +# binary using the provided name. +# +# Set BINARY_NAME to the name of the binary file to build. +# Set BUILD_TYPE to either debug or release +# +# Automatic dependencies code from: +# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr +BINARY_NAME=pile_contigue +BUILD_TYPE=debug + +# ==================================== +# DO NOT CHANGE STUFF BEYOND THIS LINE +# ==================================== + +all: $(BINARY_NAME) + +CC=gcc +LD=gcc + +WARN_FLAGS = -Wall -Wextra +STD_FLAG = -std=c99 + +ifeq ($(BUILD_TYPE),debug) +BUILDDIR := .build/debug +DEBUG_FLAG = -g +STRIP_FLAG = +OPTI_FLAG = -O0 +else +BUILDDIR := .build/release +DEBUG_FLAG = +STRIP_FLAG = -s +OPTIFLAG = -O3 +endif + +CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) +LDFLAGS := $(LDFLAGS) $(STRIP_FLAG) + +OBJDIR := $(BUILDDIR)/objs +$(shell mkdir -p $(OBJDIR)) + +SRCS=$(wildcard *.c) +OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(SRCS)) + +DEPDIR := $(BUILDDIR)/deps +$(shell mkdir -p $(DEPDIR)) +DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td +POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d + +$(BINARY_NAME): $(OBJS) + @echo "[LD ] $@" + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d + @echo "[C ] $*" + @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@ + @$(POSTCOMPILE) + +$(DEPDIR)/%.d: ; + +.PRECIOUS: $(DEPDIR)/%.d + +include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))) + +clean: + @echo "[CLN]" + -@rm -r $(BUILDDIR) + -@rm $(BINARY_NAME) + +disassemble: $(BINARY_NAME) + objdump -d $< | less + +symbols: $(BINARY_NAME) + objdump -t $< | sort | less diff --git a/TP5/exo1/pile_contigue.c b/TP5/exo1/pile_contigue.c new file mode 100644 index 0000000..4a3adc0 --- /dev/null +++ b/TP5/exo1/pile_contigue.c @@ -0,0 +1,62 @@ +/******************************************************************************* + Implantation contiguë d'un type Pile d'entiers + +La pile est représentée par une structure: + un tableau représente les valeurs + un entier représente le nombre d'éléments de la pile +*******************************************************************************/ +#include +#include + +#define LONG_PILE 25 +typedef int element; +typedef struct { int nbre; + element tab[LONG_PILE];} Pile; + +Pile pile_vide(void) +{ Pile p; p.nbre=0; + return p; +} + +int est_vide(Pile p) +{ return p.nbre==0; /* ou return !p.nbre; */ +} + +element sommet(Pile p) +/* ATTENTION: consulter le sommet d'une pile vide n'a pas de sens */ +{ if (est_vide(p)) { printf("Erreur - pile vide\n"); exit(-1); } + return p.tab[p.nbre-1]; +} +Pile empiler(element e,Pile p) +{ if (p.nbre==LONG_PILE) { printf("Erreur - pile pleine\n"); exit(-1); } +p.tab[p.nbre++]=e; + return p; +} + +Pile depiler(Pile p) +/* ATTENTION: supprimer le sommet d'une pile vide n'a pas de sens */ +{ if (est_vide(p)) { printf("Erreur - pile vide\n"); exit(-1); } +p.nbre--; + return p; +} + +element depiler2(Pile *p) /* ATTENTION: la pile est modifiée */ +/* ATTENTION: dépiler une pile vide n'a pas de sens */ +{ if (est_vide(*p)) { printf("Erreur - pile vide\n"); exit(-1); } +return p->tab[p->nbre-- -1]; +} +/******************************************************************************/ + + +int main() +{Pile p; + int i; + + p=pile_vide(); + + for (i=0; i<20; i++) p=empiler(i,p); + + for (i=0; i<25; i++) printf("%d\n",depiler2(&p)); +} +/********************************************************************/ + diff --git a/TP5/exo2/Makefile b/TP5/exo2/Makefile new file mode 100644 index 0000000..06b81e5 --- /dev/null +++ b/TP5/exo2/Makefile @@ -0,0 +1,79 @@ +# Sample Makefile to build simple project. +# +# This Makefile expect all source files (.c) to be at the same level, in the +# current working directory. +# +# It will automatically generate dependencies, compile all files, and produce a +# binary using the provided name. +# +# Set BINARY_NAME to the name of the binary file to build. +# Set BUILD_TYPE to either debug or release +# +# Automatic dependencies code from: +# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr +BINARY_NAME=pile_realloc +BUILD_TYPE=debug + +# ==================================== +# DO NOT CHANGE STUFF BEYOND THIS LINE +# ==================================== + +all: $(BINARY_NAME) + +CC=gcc +LD=gcc + +WARN_FLAGS = -Wall -Wextra +STD_FLAG = -std=c99 + +ifeq ($(BUILD_TYPE),debug) +BUILDDIR := .build/debug +DEBUG_FLAG = -g +STRIP_FLAG = +OPTI_FLAG = -O0 +else +BUILDDIR := .build/release +DEBUG_FLAG = +STRIP_FLAG = -s +OPTIFLAG = -O3 +endif + +CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) +LDFLAGS := $(LDFLAGS) $(STRIP_FLAG) + +OBJDIR := $(BUILDDIR)/objs +$(shell mkdir -p $(OBJDIR)) + +SRCS=$(wildcard *.c) +OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(SRCS)) + +DEPDIR := $(BUILDDIR)/deps +$(shell mkdir -p $(DEPDIR)) +DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td +POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d + +$(BINARY_NAME): $(OBJS) + @echo "[LD ] $@" + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d + @echo "[C ] $*" + @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@ + @$(POSTCOMPILE) + +$(DEPDIR)/%.d: ; + +.PRECIOUS: $(DEPDIR)/%.d + +include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))) + +clean: + @echo "[CLN]" + -@rm -r $(BUILDDIR) + -@rm $(BINARY_NAME) + +disassemble: $(BINARY_NAME) + objdump -d $< | less + +symbols: $(BINARY_NAME) + objdump -t $< | sort | less diff --git a/TP5/exo2/pile_realloc.c b/TP5/exo2/pile_realloc.c new file mode 100644 index 0000000..a41cdb7 --- /dev/null +++ b/TP5/exo2/pile_realloc.c @@ -0,0 +1,65 @@ +/********************************************************************/ +/* Implantation contiguë d'un type Pile d'entiers */ +/* On rallonge le tableau par realloc quand il est plein */ +/********************************************************************/ +#include +#include + +#define LONG_PILE 5 +typedef int element; +typedef struct { int nbre; + int taille_tab; + element *tab; } Pile; + +Pile pile_vide(void) +{Pile p; p.nbre=0; p.taille_tab=LONG_PILE; + p.tab=(element *)calloc(p.taille_tab, sizeof(element)); + return p; +} + +int est_vide(Pile p) +{return p.nbre==0; /* ou return !p.nbre; */ +} + +element sommet(Pile p) +/* ATTENTION: consulter le sommet d'une pile vide n'a pas de sens */ +{if (est_vide(p)) { printf("Erreur - pile vide\n"); exit(-1); } + return p.tab[p.nbre-1]; +} + +Pile empiler(element e,Pile p) +{if (p.nbre==p.taille_tab) + {printf("pile pleine %d - on la rallonge!\n",p.taille_tab); + p.taille_tab *=2; + p.tab=realloc(p.tab, p.taille_tab*sizeof(element)); + } + p.tab[p.nbre++]=e; + return p; +} + +Pile depiler(Pile p) +/* ATTENTION: supprimer le sommet d'une pile vide n'a pas de sens */ +{if (est_vide(p)) { printf("Erreur - pile vide\n"); exit(-1); } + p.nbre--; + return p; +} + +element depiler2(Pile *p) /* ATTENTION: la pile est modifiée */ +/* ATTENTION: dépiler une pile vide n'a pas de sens */ +{if (est_vide(*p)) { printf("Erreur - pile vide\n"); exit(-1); } + return p->tab[p->nbre-- -1]; +} +/********************************************************************/ + +int main() +{Pile p; + int i; + + p=pile_vide(); + + for (i=0; i<20; i++) p=empiler(i,p); + + for (i=0; i<25; i++) printf("%d\n",depiler2(&p)); +} +/********************************************************************/ + diff --git a/TP5/exo3/Makefile b/TP5/exo3/Makefile new file mode 100644 index 0000000..71cfe81 --- /dev/null +++ b/TP5/exo3/Makefile @@ -0,0 +1,79 @@ +# Sample Makefile to build simple project. +# +# This Makefile expect all source files (.c) to be at the same level, in the +# current working directory. +# +# It will automatically generate dependencies, compile all files, and produce a +# binary using the provided name. +# +# Set BINARY_NAME to the name of the binary file to build. +# Set BUILD_TYPE to either debug or release +# +# Automatic dependencies code from: +# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr +BINARY_NAME=file_contigue +BUILD_TYPE=debug + +# ==================================== +# DO NOT CHANGE STUFF BEYOND THIS LINE +# ==================================== + +all: $(BINARY_NAME) + +CC=gcc +LD=gcc + +WARN_FLAGS = -Wall -Wextra +STD_FLAG = -std=c99 + +ifeq ($(BUILD_TYPE),debug) +BUILDDIR := .build/debug +DEBUG_FLAG = -g +STRIP_FLAG = +OPTI_FLAG = -O0 +else +BUILDDIR := .build/release +DEBUG_FLAG = +STRIP_FLAG = -s +OPTIFLAG = -O3 +endif + +CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) +LDFLAGS := $(LDFLAGS) $(STRIP_FLAG) + +OBJDIR := $(BUILDDIR)/objs +$(shell mkdir -p $(OBJDIR)) + +SRCS=$(wildcard *.c) +OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(SRCS)) + +DEPDIR := $(BUILDDIR)/deps +$(shell mkdir -p $(DEPDIR)) +DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td +POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d + +$(BINARY_NAME): $(OBJS) + @echo "[LD ] $@" + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d + @echo "[C ] $*" + @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@ + @$(POSTCOMPILE) + +$(DEPDIR)/%.d: ; + +.PRECIOUS: $(DEPDIR)/%.d + +include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))) + +clean: + @echo "[CLN]" + -@rm -r $(BUILDDIR) + -@rm $(BINARY_NAME) + +disassemble: $(BINARY_NAME) + objdump -d $< | less + +symbols: $(BINARY_NAME) + objdump -t $< | sort | less diff --git a/TP5/exo3/file_contigue.c b/TP5/exo3/file_contigue.c new file mode 100644 index 0000000..7908535 --- /dev/null +++ b/TP5/exo3/file_contigue.c @@ -0,0 +1,70 @@ +/************************************************************************** + Implantation contiguë d'un type File d'entiers + + La File est représentée par une structure: + un tableau représente les valeurs + un entier représente la position de la tête de la File + un entier représente la position de la queue de la File + + le tableau est exploité de façon circulaire. +**************************************************************************/ +#include +#include + +#define LONG_FILE 25 + +typedef int element; +typedef struct { int tete; + int queue; + element tab[LONG_FILE]; } File; + +File file_vide(void) +{ File f={0,0}; /* f.tete=f.queue=0 */ + return f; +} + +int est_vide(File f) { return f.tete==f.queue; } + +int est_pleine(File f) { return (f.queue+1)%LONG_FILE==f.tete; } + +element tete(File f) +/* ATTENTION: consulter la tête d'une File vide n'a pas de sens */ +{ if (est_vide(f)) { printf("Erreur - file vide\n"); exit(-1); } +return f.tab[f.tete]; +} +File enfiler(element e,File f) +{ if (est_pleine(f)) { printf("Erreur - file pleine\n"); exit(-1); } + f.tab[f.queue]=e; f.queue=(f.queue+1)%LONG_FILE; + return f; +} + +File defiler(File f) +/* ATTENTION: supprimer la tête d'une File vide n'a pas de sens */ +{ if (est_vide(f)) { printf("Erreur - file vide\n"); exit(-1); } + f.tete=(f.tete+1)%LONG_FILE; + return f; +} + +element defiler2(File * f) /*ATTENTION: la File est modifiée */ +/* ATTENTION: défiler une File vide n'a pas de sens */ +{ element e; + if (est_vide(*f)) { printf("Erreur - file vide\n"); exit(-1); } +e=f->tab[f->tete]; + f->tete=(f->tete+1)%LONG_FILE; + return e; +} +/*************************************************************************/ + + +int main() +{File p; + int i; + + p=file_vide(); + + for (i=0; i<20; i++) p=enfiler(i,p); + + for (i=0; i<25; i++) printf("%d\n",defiler2(&p)); +} +/********************************************************************/ + diff --git a/TP5/exo4/Makefile b/TP5/exo4/Makefile new file mode 100644 index 0000000..6f1791e --- /dev/null +++ b/TP5/exo4/Makefile @@ -0,0 +1,79 @@ +# Sample Makefile to build simple project. +# +# This Makefile expect all source files (.c) to be at the same level, in the +# current working directory. +# +# It will automatically generate dependencies, compile all files, and produce a +# binary using the provided name. +# +# Set BINARY_NAME to the name of the binary file to build. +# Set BUILD_TYPE to either debug or release +# +# Automatic dependencies code from: +# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr +BINARY_NAME=list_chainee +BUILD_TYPE=debug + +# ==================================== +# DO NOT CHANGE STUFF BEYOND THIS LINE +# ==================================== + +all: $(BINARY_NAME) + +CC=gcc +LD=gcc + +WARN_FLAGS = -Wall -Wextra +STD_FLAG = -std=c99 + +ifeq ($(BUILD_TYPE),debug) +BUILDDIR := .build/debug +DEBUG_FLAG = -g +STRIP_FLAG = +OPTI_FLAG = -O0 +else +BUILDDIR := .build/release +DEBUG_FLAG = +STRIP_FLAG = -s +OPTIFLAG = -O3 +endif + +CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) +LDFLAGS := $(LDFLAGS) $(STRIP_FLAG) + +OBJDIR := $(BUILDDIR)/objs +$(shell mkdir -p $(OBJDIR)) + +SRCS=$(wildcard *.c) +OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(SRCS)) + +DEPDIR := $(BUILDDIR)/deps +$(shell mkdir -p $(DEPDIR)) +DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td +POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d + +$(BINARY_NAME): $(OBJS) + @echo "[LD ] $@" + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d + @echo "[C ] $*" + @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@ + @$(POSTCOMPILE) + +$(DEPDIR)/%.d: ; + +.PRECIOUS: $(DEPDIR)/%.d + +include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))) + +clean: + @echo "[CLN]" + -@rm -r $(BUILDDIR) + -@rm $(BINARY_NAME) + +disassemble: $(BINARY_NAME) + objdump -d $< | less + +symbols: $(BINARY_NAME) + objdump -t $< | sort | less diff --git a/TP5/exo4/liste_a_completer.c b/TP5/exo4/liste_a_completer.c new file mode 100644 index 0000000..b7494f0 --- /dev/null +++ b/TP5/exo4/liste_a_completer.c @@ -0,0 +1,116 @@ +/********************************************************************/ +/* Implantation d'une liste triee d'entiers */ +/********************************************************************/ +#include +#include + +typedef int element; + +typedef struct cellule { + element valeur; + struct cellule *suivant; +} Cellule, *Liste; + + +Liste ajouter_iter(element e, Liste L) +{Cellule *pc, *p1=L, *p2=NULL; + + pc = (Cellule *)malloc(sizeof(Cellule)); + pc->valeur=e; + pc->suivant=NULL; + + if (!L) /* liste vide */ return pc; + + while (p1 && (e >= p1->valeur)) + {p2 = p1; + p1 = p1->suivant;} + + if (!p2) /* insertion en tete */ + {pc->suivant = L; + L=pc; } + else /* insertion entre p2 et p1 */ + {p2->suivant = pc; + pc->suivant = p1; } + + return L; +} + + +int longueur_iter(Liste L) +{ + return 0; /* ... */ +} + + +int longueur_rec(Liste L) +{ + /* ... */ +} + + +void visualiser_iter(Liste L) +{ + /* ... */ +} + + +void visualiser_rec(Liste L) +{ + /* ... */ +} + + +int rechercher_iter(element e, Liste L) +{ + /* ... */ +} + + +Liste rechercher_rec(element e, Liste L) +{ + /* ... */ +} + + +Liste ajouter_rec(element e, Liste L) +{ + /* ... */ +} + + +Liste supprimer_iter(element e, Liste L) +{ + /* ... */ +} + +Liste supprimer_rec(element e, Liste L) +{ + /* ... */ +} + + +Liste inverser_iter(Liste L) +{ + /* ... */ +} + + +Liste inverser_rec(Liste L) +{ + /* ... */ +} + + +/****************************************************************************/ +int main() +{ + int x; + Liste L=NULL; + scanf("%d",&x); + L=ajouter_iter(x,L); + printf("longueur=%d\n",longueur_iter(L)); + visualiser_iter(L); + /* ... */ +} +/****************************************************************************/ + diff --git a/TP5/exo5/Makefile b/TP5/exo5/Makefile new file mode 100644 index 0000000..ec1c41a --- /dev/null +++ b/TP5/exo5/Makefile @@ -0,0 +1,79 @@ +# Sample Makefile to build simple project. +# +# This Makefile expect all source files (.c) to be at the same level, in the +# current working directory. +# +# It will automatically generate dependencies, compile all files, and produce a +# binary using the provided name. +# +# Set BINARY_NAME to the name of the binary file to build. +# Set BUILD_TYPE to either debug or release +# +# Automatic dependencies code from: +# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr +BINARY_NAME=pile_chainee +BUILD_TYPE=debug + +# ==================================== +# DO NOT CHANGE STUFF BEYOND THIS LINE +# ==================================== + +all: $(BINARY_NAME) + +CC=gcc +LD=gcc + +WARN_FLAGS = -Wall -Wextra +STD_FLAG = -std=c99 + +ifeq ($(BUILD_TYPE),debug) +BUILDDIR := .build/debug +DEBUG_FLAG = -g +STRIP_FLAG = +OPTI_FLAG = -O0 +else +BUILDDIR := .build/release +DEBUG_FLAG = +STRIP_FLAG = -s +OPTIFLAG = -O3 +endif + +CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) +LDFLAGS := $(LDFLAGS) $(STRIP_FLAG) + +OBJDIR := $(BUILDDIR)/objs +$(shell mkdir -p $(OBJDIR)) + +SRCS=$(wildcard *.c) +OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(SRCS)) + +DEPDIR := $(BUILDDIR)/deps +$(shell mkdir -p $(DEPDIR)) +DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td +POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d + +$(BINARY_NAME): $(OBJS) + @echo "[LD ] $@" + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d + @echo "[C ] $*" + @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@ + @$(POSTCOMPILE) + +$(DEPDIR)/%.d: ; + +.PRECIOUS: $(DEPDIR)/%.d + +include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))) + +clean: + @echo "[CLN]" + -@rm -r $(BUILDDIR) + -@rm $(BINARY_NAME) + +disassemble: $(BINARY_NAME) + objdump -d $< | less + +symbols: $(BINARY_NAME) + objdump -t $< | sort | less diff --git a/TP5/exo5/pile_chainee_a_completer.c b/TP5/exo5/pile_chainee_a_completer.c new file mode 100644 index 0000000..1eede6d --- /dev/null +++ b/TP5/exo5/pile_chainee_a_completer.c @@ -0,0 +1,55 @@ +/*************************************************************** + Implantation d'un type Pile d'entiers sous forme chaînée + La pile est représentée par un pointeur. + La pile vide est représentée par NULL. +****************************************************************/ + +#include +#include + +typedef int element; + +typedef struct cellule +{ + element valeur; + struct cellule *suivant; +} Cellule, *Pile; + + +Pile pile_vide(void) +{ +} + +int est_vide(Pile p) +{ +} + +element sommet(Pile p) +/* ATTENTION: consulter le sommet d'une pile vide n'a pas de sens */ +{ + /* la pile n'est pas modifiée */ +} + +Pile empiler(element e, Pile p) +{ +} + +Pile depiler(Pile p) +/* ATTENTION: supprimer le sommet d'une pile vide n'a pas de sens */ +{ +} + +element depiler2(Pile * p) /*ATTENTION: la pile est modifiée */ +/* ATTENTION: cette opération n'a pas de sens avec une pile vide */ +{ +} + + +/******************************************************************************/ +int main() +{Pile p; + int i; + p=pile_vide(); + for (i=0; i<20; i++) p=empiler(i,p); + for (i=0; i<25; i++) printf("%d\n",depiler2(&p));} +/******************************************************************************/ diff --git a/TP5/exo6/Makefile b/TP5/exo6/Makefile new file mode 100644 index 0000000..959f919 --- /dev/null +++ b/TP5/exo6/Makefile @@ -0,0 +1,79 @@ +# Sample Makefile to build simple project. +# +# This Makefile expect all source files (.c) to be at the same level, in the +# current working directory. +# +# It will automatically generate dependencies, compile all files, and produce a +# binary using the provided name. +# +# Set BINARY_NAME to the name of the binary file to build. +# Set BUILD_TYPE to either debug or release +# +# Automatic dependencies code from: +# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr +BINARY_NAME=file_chainee +BUILD_TYPE=debug + +# ==================================== +# DO NOT CHANGE STUFF BEYOND THIS LINE +# ==================================== + +all: $(BINARY_NAME) + +CC=gcc +LD=gcc + +WARN_FLAGS = -Wall -Wextra +STD_FLAG = -std=c99 + +ifeq ($(BUILD_TYPE),debug) +BUILDDIR := .build/debug +DEBUG_FLAG = -g +STRIP_FLAG = +OPTI_FLAG = -O0 +else +BUILDDIR := .build/release +DEBUG_FLAG = +STRIP_FLAG = -s +OPTIFLAG = -O3 +endif + +CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) +LDFLAGS := $(LDFLAGS) $(STRIP_FLAG) + +OBJDIR := $(BUILDDIR)/objs +$(shell mkdir -p $(OBJDIR)) + +SRCS=$(wildcard *.c) +OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(SRCS)) + +DEPDIR := $(BUILDDIR)/deps +$(shell mkdir -p $(DEPDIR)) +DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td +POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d + +$(BINARY_NAME): $(OBJS) + @echo "[LD ] $@" + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d + @echo "[C ] $*" + @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@ + @$(POSTCOMPILE) + +$(DEPDIR)/%.d: ; + +.PRECIOUS: $(DEPDIR)/%.d + +include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))) + +clean: + @echo "[CLN]" + -@rm -r $(BUILDDIR) + -@rm $(BINARY_NAME) + +disassemble: $(BINARY_NAME) + objdump -d $< | less + +symbols: $(BINARY_NAME) + objdump -t $< | sort | less diff --git a/TP5/exo6/file_chainee_a_completer.c b/TP5/exo6/file_chainee_a_completer.c new file mode 100644 index 0000000..2ec62db --- /dev/null +++ b/TP5/exo6/file_chainee_a_completer.c @@ -0,0 +1,67 @@ +/*********************************************************************** + Implantation d'un type File d'entiers sous forme chaînée + + La file est représentée par un doublet tête-queue de pointeurs + vers une cellule. + Le pointeur "tête" contient l'adresse de la tête de la file. + Le pointeur "queue" contient l'adresse de la queue de la file. + La file vide est représentée par le doublet NULL-NULL + + Chaque cellule pointe vers la cellule suivante de la file + ou vers NULL si on est en queue de file. +***********************************************************************/ +#include +#include + +typedef int element; + +typedef struct cellule +{ + element valeur; + struct cellule *suivant; +} Cellule; + +typedef struct file +{ + Cellule *t, *q; +} File; /* tête queue */ + + +File file_vide(void) +{ +} + +int est_vide(File f) +{ +} + +element tete(File f) +/* ATTENTION: consulter la tête d'une File vide n'a pas de sens */ +{ + /* la File n'est pas modifiée */ +} + +File enfiler(element e,File f) +{ +} + +File defiler(File f) +/* ATTENTION: supprimer la tête d'une File vide n'a pas de sens */ +{ +} + +element defiler2(File *f) /* ATTENTION: la File est modifiée */ +/* ATTENTION: supprimer la tête d'une File vide n'a pas de sens */ +{ +} + + +/********************************************************************/ +int main() +{File p; + int i; + p=file_vide(); + for (i=0; i<20; i++) p=enfiler(i,p); + for (i=0; i<25; i++) printf("%d\n",defiler2(&p));} + /********************************************************************/ + \ No newline at end of file