diff --git a/bp_tree.c b/bp_tree.c index 6b80f94b89e201e4709cd85f790c95a54c6ba75e..d562e9e03b4dbf7c59bf9a3dda0d122d5f743759 100644 --- a/bp_tree.c +++ b/bp_tree.c @@ -74,6 +74,7 @@ node *bp_split(node *nd) { // childs for leaves for (int i = 0; i < upto; i++) { new->data[i] = nd->data[index + i]; + new->user[i] = nd->user[index + i]; nd->data[index + i] = 0; } @@ -285,9 +286,8 @@ node *bp_insert_val(node *tree, entry person) { // SEARCH ---------------------------------------------------------- entry bp_search_node(node *tree, uint64_t hash) { - if (tree == NULL) { + if (tree == NULL) return CONST_ENTR; - } if (bp_is_leaf(tree)) { for (int i = 0; i < M; i++) { @@ -295,11 +295,12 @@ entry bp_search_node(node *tree, uint64_t hash) { return tree->user[i]; } } else { - for (int i = 0; i <= M; i++) { - if (tree->data[i] > hash) { + for (int i = 0; i < M; i++) { + if (tree->data[i] > hash || tree->data[i] == 0) { return bp_search_node(tree->childs[i], hash); } } + return bp_search_node(tree->childs[M], hash); } return CONST_ENTR; } @@ -400,7 +401,7 @@ void bp_print_as_ll(node *root) { return bp_print_as_ll(root->childs[0]); } - printf("|"); + printf("| "); // print every values in the node until hitting 0, then we can get on the // next node for (int i = 0; i < M; i++) { diff --git a/main.c b/main.c index 0d8a31dade6539d32ec2b08af359a3d9888306b0..8fe32eccf8aaa40f2a8397a78a7c53e27b72a5ca 100644 --- a/main.c +++ b/main.c @@ -33,15 +33,15 @@ int main() { tree = bp_insert_val(tree, person); strcpy(person.f_name, "Vincent\0"); - strcpy(person.l_name, "\0"); + strcpy(person.l_name, "Steinmann\0"); strcpy(person.phone, "0795787730\0"); test.day = 24; test.month = 5; - test.year = 101; + test.year = 97; person.birth = test; tree = bp_insert_val(tree, person); - char phone_search[11] = {"0788909566"}; + char phone_search[11] = {"0795787730"}; bp_print(tree, 0); printf("\n|||||||||\n"); printf("Recherche par n° de téléphone : \n");