diff options
Diffstat (limited to 'semestre 3/structures des données/td')
| -rw-r--r-- | semestre 3/structures des données/td/td4/exo1.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/semestre 3/structures des données/td/td4/exo1.c b/semestre 3/structures des données/td/td4/exo1.c new file mode 100644 index 0000000..aa4f7c0 --- /dev/null +++ b/semestre 3/structures des données/td/td4/exo1.c @@ -0,0 +1,49 @@ +#include <stdio.h> + +typedef struct _Cell { + Formation* val; + struct _Cell* next; +} Cell; + +typedef struct _Formation { + char* name; + int hours; + Cell* formations; +} Formation; + +typedef struct{ + int length; + int max; + Formations** formations; +} Catalogue; + +void print_formation(Formation* f){ + if (f->hours != 0) { + printf("Cours %s\n", f->name); + return; + } + printf("%s (%d): ", f->name, f->hours); + Cell* fms = f->formations; + while (fms) { + print_formation(fms->val); + fms = fms->next; + } + printf("\n"); +} + +void print_catalogue(Catalogue* c){ + for (int i = 0; i < c->lenght; i++) { + print_formation(c->formations[i]); + } +} + +int sum_formation_hours(Formation* f, int acc){ + acc += f->hours; + Cell* fms = f->formations; + while (fms){ + acc += sum_formation_hours(fms, acc); + fms = fms->next; + } + return acc; +} + |
