From acbd5bf3cfc45a541a3c9aa331a4abba239a1cad Mon Sep 17 00:00:00 2001
From: Alec <alec.schmidt@hesge.ch>
Date: Thu, 2 Jun 2022 14:58:10 +0200
Subject: [PATCH] =?UTF-8?q?fonction=20pour=20print=20l'enti=C3=A8ret=C3=A9?=
 =?UTF-8?q?=20des=20entr=C3=A9es?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 bp_tree.c | 19 +++++++++++++++++++
 bp_tree.h |  2 ++
 main.c    |  3 ++-
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/bp_tree.c b/bp_tree.c
index d562e9e..97fa2ef 100644
--- a/bp_tree.c
+++ b/bp_tree.c
@@ -329,6 +329,25 @@ void bp_destroy(node *root) {
 
 // PRINTING ----------------------------------------------------------
 
+void bp_print_everything(node *tree) { // if we reached the end of the list
+    if (tree == NULL)
+        return;
+
+    // search for the first leaf on the tree
+    if (!bp_is_leaf(tree)) {
+        return bp_print_everything(tree->childs[0]);
+    }
+    // print every values in the node until hitting 0, then we can get on the
+    // next node
+    for (int i = 0; i < M; i++) {
+        bp_print_entry(tree->user[i]);
+        printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
+        if (tree->data[i + 1] == 0) {
+            return bp_print_everything(tree->next);
+        }
+    }
+}
+
 void print_date(date item) {
     printf("%d - ", item.day);
 
diff --git a/bp_tree.h b/bp_tree.h
index f04e9b9..b33052f 100644
--- a/bp_tree.h
+++ b/bp_tree.h
@@ -39,6 +39,8 @@ void bp_print(node *root, int depth);
 
 void bp_print_entry(entry person);
 
+void bp_print_everything(node *tree);
+
 void bp_search(node *tree, char phone[11]);
 
 /**
diff --git a/main.c b/main.c
index 8fe32ec..89374af 100644
--- a/main.c
+++ b/main.c
@@ -44,8 +44,9 @@ int main() {
     char phone_search[11] = {"0795787730"};
     bp_print(tree, 0);
     printf("\n|||||||||\n");
-    printf("Recherche par n° de téléphone : \n");
 
+    bp_print_everything(tree);
+    printf("\nRecherche par n° de téléphone : \n");
     bp_search(tree, phone_search);
 
     /*
-- 
GitLab