From 4ed8060318b1807638c12b8b43660bb98fc99fba Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Fri, 10 Oct 2025 23:15:18 +0200 Subject: Cours du 6 au 10 octobre --- .../structures des donn\303\251es/td/td4/exo1.c" | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "semestre 3/structures des donn\303\251es/td/td4/exo1.c" (limited to 'semestre 3/structures des données/td/td4') diff --git "a/semestre 3/structures des donn\303\251es/td/td4/exo1.c" "b/semestre 3/structures des donn\303\251es/td/td4/exo1.c" new file mode 100644 index 0000000..aa4f7c0 --- /dev/null +++ "b/semestre 3/structures des donn\303\251es/td/td4/exo1.c" @@ -0,0 +1,49 @@ +#include + +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; +} + -- cgit v1.2.3