From 6b30677698e482175887ca866cd856f0c847cd0c Mon Sep 17 00:00:00 2001 From: Hofmann Jonas Date: Tue, 9 Dec 2025 01:00:42 +0100 Subject: [PATCH] addToTreeExpandsTreeCorrectly --- bintree.c | 25 +++++++++++++++++-------- bintree.o | Bin 2665 -> 2717 bytes bintreeTests.c | 5 +++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/bintree.c b/bintree.c index 6cf26f9..a7846be 100644 --- a/bintree.c +++ b/bintree.c @@ -51,27 +51,35 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType compareFct, int *isDuplicate) { printf("entered addRec\n"); - if (currentNode == NULL) + if ((currentNode == NULL)) { printf("currentNode == NULL\n"); - if (isDuplicate != NULL) + if (isDuplicate == NULL) { - *isDuplicate = 0; + + return newNode; + } + //else if (isDuplicate != 1) + //{ + // *isDuplicate = 0; + // return newNode; + //} + else + { + return currentNode; } - - return newNode; } - else if (compareFct(¤tNode->data, &newNode->data) < 0) + else if ((compareFct(¤tNode->data, &newNode->data) < 0)) { printf("compareFct(currentNode->data, newNode->data) < 0\n"); currentNode->left = addToTreeRec(currentNode->left, newNode, compareFct, isDuplicate); } - else if (compareFct(¤tNode->data, &newNode->data) > 0) + else if ((compareFct(¤tNode->data, &newNode->data) > 0)) { printf("compareFct(currentNode->data, newNode->data) > 0\n"); currentNode->right = addToTreeRec(currentNode->right, newNode, compareFct, isDuplicate); } - else if (compareFct(¤tNode->data, &newNode->data) == 0) + else if ((compareFct(¤tNode->data, &newNode->data) == 0)) { //duplicate printf("duplicate\n"); @@ -81,6 +89,7 @@ TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType } else { + printf("setDuplicate\n"); *isDuplicate = 1; } } diff --git a/bintree.o b/bintree.o index e53f36e3003b527a372829f3c3d34987b1c1f7ad..d193ca1c6e01704e3fd298d97f3a725791bdbe2c 100644 GIT binary patch delta 567 zcmaDUGFOx{`geRJ2GtQZ~P@U}u3j>21`^0l{ ztOtNn5feYEGfA*bmSVi2so~Mf$`2It=sfrWq|2kZR)e9G)1%u};-wMLEFeSRr6!Ou z`5=?XWCJFB!Q}t{|9fmruo)DoA;w^-#Se`TFn&jGYl z3@FXQAOK{^fLSqcu@t!2TDaI&xY&ER*mt-X2hd8Wc|aD#yrn>vEZF2La2AjY^3vv? zY_W{dAb&A3C@=siATS1Ekna#8wm=b(9}yy6KoO8nAtEJ3sj0!4RjDBVBGiNc)d)}C X$RW*|3iP}11i delta 539 zcmbO$`ci}|rH!2d1Rk+Z2u?K3X6%``P@U}s3j@O^wu$HD zST_KrJSKirXZ$hoqwr)M#$#HV9=)vmAkof)FF^V{nrk%}O1M0_T{Vt__zXan#7ill zxswktiA>gK(icqn|Np;7cc_3zrxVA^%|In!nPw(^K0btu!0RNSuqdO?left->left->left); TEST_ASSERT_EQUAL_UINT16(score4, testRoot->left->left->left->data); + printf("double passed\n"); // Trying to add Double while Doubles not Permitted - testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, testIsDouble); + testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, &testIsDouble); TEST_ASSERT_NULL(testRoot->right->right->left); TEST_ASSERT_EQUAL_UINT16(1, testIsDouble);