From 36ac0d6d9d3c4b2e9a9dc0db4d4a67cbcdfaa540 Mon Sep 17 00:00:00 2001 From: Hofmann Jonas Date: Tue, 9 Dec 2025 00:36:27 +0100 Subject: [PATCH] normal Nodes working in addToTree() --- bintree.c | 10 ++++------ bintree.o | Bin 2629 -> 2665 bytes bintreeTests.c | 21 ++++++++++++++++----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/bintree.c b/bintree.c index 3c34c42..6cf26f9 100644 --- a/bintree.c +++ b/bintree.c @@ -50,9 +50,7 @@ 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"); - //printf("curdat = %d\n", currentNode->data); - //printf("newdat = %d\n", newNode->data); + printf("entered addRec\n"); if (currentNode == NULL) { printf("currentNode == NULL\n"); @@ -63,17 +61,17 @@ TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType return newNode; } - else if (compareFct(currentNode->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(currentNode->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(currentNode->data, newNode->data) == 0) + else if (compareFct(¤tNode->data, &newNode->data) == 0) { //duplicate printf("duplicate\n"); diff --git a/bintree.o b/bintree.o index f472e9eb2c68e7dd89c2c522cba49d3946327894..e53f36e3003b527a372829f3c3d34987b1c1f7ad 100644 GIT binary patch delta 617 zcmX>q@=}B|rH!2d1RhP~ROa+x1G5Cwx|KluftqMQ^XP_8>v!lT<&z^B_)0jSRL|Ap2Am3BZS8k2RI zG_{ld|NjqEBH+>K#PM=7$Sf@C>#Tw56DGGaX=?Bx)C;^$!lt;?2dH@BDOw3y=+>!+|&e$WF~GNi9lEQAkWl2}(_7NG>fZ0t)%%r=%*_+A8>k z`uG490YP$pZb4#E>g06R_w`$Vd@&$qVb}vCWx%XcaIs5pF-~A0LevQYSrB!xaIsXl z*gCk_Hn`X?xEK@Ad+)ZomjR8Z(3)Pw-luuksfkY)vilHlaE9P1g^PIMHVT*P@902CU4 A%>V!Z delta 580 zcmaDUa#VyfrH!2d1olnjROYl`1G5?UCz?)YJU8*IJmZ3iZ?zd;O#CQ3S%+~GS97fZ zL#d`mFDt|3?~IBnI*beq9^I}I9^C>!3Wynex?L4KIuAPjztDQ1(hjIlVzL>NreXH~ z|NlL@Lj^oKoj6|Z2ik#KSDiIbSHR>hCQUs-gf4;C8Mw8S`T(^wPQJ}#z_@ub53>|w z_hxnGB*w`XSR^JdVF^hVW@2FA0a^;8<$zcM$Oh52K&${{gXm@;)&a6X^c^6!0J1?e z2QveM3y=+>qkuR7$WAUTDoV{O@ykz1Rj{>H@C)_vnVik~yM8xNP7H`y7!CtT88C|h z7(@^;4j>C676lhef{Sg0i|vGq{e_FM0$l>pI}6B?1)F>l&H{2l{@eVMEtWAF +#include #include "unity.h" #include "bintree.h" @@ -17,10 +18,13 @@ void tearDown(void) { static int compareIntEntries(const void *arg1, const void *arg2) { // printf("in comp\n"); - const int *entry1 = (const int *)arg1; - const int *entry2 = (const int *)arg2; + const int *entry1 = (const void *)arg1; + const int *entry2 = (const void *)arg2; + // printf("const set\n"); - int result = entry2 - entry1; + int result = *entry2 - *entry1; + + // int result = entry2 - entry1; // printf("exit comp\n"); return result; @@ -45,18 +49,25 @@ void test_addToTreeExpandsTreeCorrectly(void) testRoot = addToTree(testRoot, &score1, sizeof(int), compareIntEntries, NULL); printf("add1passed\n"); + testRoot = addToTree(testRoot, &score2, sizeof(int), compareIntEntries, NULL); printf("add2passed\n"); + testRoot = addToTree(testRoot, &score3, sizeof(int), compareIntEntries, NULL); printf("add3passed\n"); + testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL); printf("add4passed\n"); + testRoot = addToTree(testRoot, &score5, sizeof(int), compareIntEntries, NULL); printf("add5passed\n"); + testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL); printf("add6passed\n"); + /* testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL); printf("add7passed\n"); + */ // Checking the Tree without Doubles TEST_ASSERT_NOT_NULL(testRoot); @@ -70,7 +81,7 @@ void test_addToTreeExpandsTreeCorrectly(void) TEST_ASSERT_NOT_NULL(testRoot->right); TEST_ASSERT_EQUAL_UINT16(score3, testRoot->right->data); printf("node3passed\n"); - + TEST_ASSERT_NOT_NULL(testRoot->left->left); TEST_ASSERT_EQUAL_UINT16(score4, testRoot->left->left->data); printf("node4passed\n"); @@ -78,7 +89,7 @@ void test_addToTreeExpandsTreeCorrectly(void) TEST_ASSERT_NOT_NULL(testRoot->left->right); TEST_ASSERT_EQUAL_UINT16(score5, testRoot->left->right->data); printf("node5passed\n"); - /* + TEST_ASSERT_NOT_NULL(testRoot->right->left); TEST_ASSERT_EQUAL_UINT16(score6, testRoot->right->left->data); printf("node6passed\n");