aboutsummaryrefslogtreecommitdiff
path: root/semestre 3/structures des données/td/td4
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-10-10 23:15:18 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2025-10-10 23:15:18 +0200
commit4ed8060318b1807638c12b8b43660bb98fc99fba (patch)
tree976f9b6be6cfbb72c3c908e2e1e60069f5a4296a /semestre 3/structures des données/td/td4
parent85fbaa4d9381e435be129aa7bc4ea6a472acb2b2 (diff)
Cours du 6 au 10 octobre
Diffstat (limited to 'semestre 3/structures des données/td/td4')
-rw-r--r--semestre 3/structures des données/td/td4/exo1.c49
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;
+}
+