removed no longer needed code
This commit is contained in:
parent
5dc45f8590
commit
402604cb45
18
bintree.c
18
bintree.c
@ -7,7 +7,7 @@
|
|||||||
//TODO: binären Suchbaum implementieren
|
//TODO: binären Suchbaum implementieren
|
||||||
/* * `addToTree`: fügt ein neues Element in den Baum ein (rekursiv), Done
|
/* * `addToTree`: fügt ein neues Element in den Baum ein (rekursiv), Done
|
||||||
* `clearTree`: gibt den gesamten Baum frei (rekursiv), Done
|
* `clearTree`: gibt den gesamten Baum frei (rekursiv), Done
|
||||||
* `treeSize`: zählt die Knoten im Baum (rekursiv),
|
* `treeSize`: zählt die Knoten im Baum (rekursiv), Done
|
||||||
* `nextTreeData`: Traversierung mit Hilfe des zuvor implementierten Stacks. */
|
* `nextTreeData`: Traversierung mit Hilfe des zuvor implementierten Stacks. */
|
||||||
|
|
||||||
|
|
||||||
@ -41,7 +41,6 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
|
|||||||
newNode->left = NULL;
|
newNode->left = NULL;
|
||||||
newNode->right = NULL;
|
newNode->right = NULL;
|
||||||
memcpy(&newNode->data, data, dataSize);
|
memcpy(&newNode->data, data, dataSize);
|
||||||
// printf("node created\n");
|
|
||||||
|
|
||||||
|
|
||||||
return addToTreeRec(root, newNode, compareFct, isDuplicate);
|
return addToTreeRec(root, newNode, compareFct, isDuplicate);
|
||||||
@ -50,20 +49,12 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
|
|||||||
|
|
||||||
TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType compareFct, int *isDuplicate)
|
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)
|
||||||
{
|
{
|
||||||
|
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
//else if (isDuplicate != 1)
|
|
||||||
//{
|
|
||||||
// *isDuplicate = 0;
|
|
||||||
// return newNode;
|
|
||||||
//}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return currentNode;
|
return currentNode;
|
||||||
@ -71,29 +62,24 @@ TreeNode *addToTreeRec(TreeNode *currentNode, TreeNode *newNode, CompareFctType
|
|||||||
}
|
}
|
||||||
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);
|
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);
|
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");
|
|
||||||
if (isDuplicate == NULL)
|
if (isDuplicate == NULL)
|
||||||
{
|
{
|
||||||
currentNode->left = addToTreeRec(currentNode->left, newNode, compareFct, isDuplicate);
|
currentNode->left = addToTreeRec(currentNode->left, newNode, compareFct, isDuplicate);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// printf("setDuplicate\n");
|
|
||||||
*isDuplicate = 1;
|
*isDuplicate = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// printf("passed everything\n");
|
|
||||||
|
|
||||||
return currentNode;
|
return currentNode;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,16 +17,12 @@ void tearDown(void) {
|
|||||||
|
|
||||||
static int compareIntEntries(const void *arg1, const void *arg2)
|
static int compareIntEntries(const void *arg1, const void *arg2)
|
||||||
{
|
{
|
||||||
// printf("in comp\n");
|
|
||||||
const int *entry1 = (const void *)arg1;
|
const int *entry1 = (const void *)arg1;
|
||||||
const int *entry2 = (const void *)arg2;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,70 +44,41 @@ void test_addToTreeExpandsTreeCorrectly(void)
|
|||||||
|
|
||||||
|
|
||||||
testRoot = addToTree(testRoot, &score1, sizeof(int), compareIntEntries, NULL);
|
testRoot = addToTree(testRoot, &score1, sizeof(int), compareIntEntries, NULL);
|
||||||
// printf("add1passed\n");
|
|
||||||
|
|
||||||
testRoot = addToTree(testRoot, &score2, sizeof(int), compareIntEntries, NULL);
|
testRoot = addToTree(testRoot, &score2, sizeof(int), compareIntEntries, NULL);
|
||||||
// printf("add2passed\n");
|
|
||||||
|
|
||||||
testRoot = addToTree(testRoot, &score3, sizeof(int), compareIntEntries, NULL);
|
testRoot = addToTree(testRoot, &score3, sizeof(int), compareIntEntries, NULL);
|
||||||
// printf("add3passed\n");
|
|
||||||
|
|
||||||
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
||||||
// printf("add4passed\n");
|
|
||||||
|
|
||||||
testRoot = addToTree(testRoot, &score5, sizeof(int), compareIntEntries, NULL);
|
testRoot = addToTree(testRoot, &score5, sizeof(int), compareIntEntries, NULL);
|
||||||
// printf("add5passed\n");
|
|
||||||
|
|
||||||
testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL);
|
testRoot = addToTree(testRoot, &score6, sizeof(int), compareIntEntries, NULL);
|
||||||
// printf("add6passed\n");
|
|
||||||
|
|
||||||
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL);
|
testRoot = addToTree(testRoot, &score7, sizeof(int), compareIntEntries, NULL);
|
||||||
// printf("add7passed\n");
|
|
||||||
|
|
||||||
|
|
||||||
// Checking the Tree without Doubles
|
// Checking the Tree without Doubles
|
||||||
TEST_ASSERT_NOT_NULL(testRoot);
|
TEST_ASSERT_NOT_NULL(testRoot);
|
||||||
TEST_ASSERT_EQUAL_UINT16(score1, testRoot->data);
|
TEST_ASSERT_EQUAL_UINT16(score1, testRoot->data);
|
||||||
// printf("node1passed\n");
|
|
||||||
|
|
||||||
TEST_ASSERT_NOT_NULL(testRoot->left);
|
TEST_ASSERT_NOT_NULL(testRoot->left);
|
||||||
TEST_ASSERT_EQUAL_UINT16(score2, testRoot->left->data);
|
TEST_ASSERT_EQUAL_UINT16(score2, testRoot->left->data);
|
||||||
// printf("node2passed\n");
|
|
||||||
|
|
||||||
TEST_ASSERT_NOT_NULL(testRoot->right);
|
TEST_ASSERT_NOT_NULL(testRoot->right);
|
||||||
TEST_ASSERT_EQUAL_UINT16(score3, testRoot->right->data);
|
TEST_ASSERT_EQUAL_UINT16(score3, testRoot->right->data);
|
||||||
// printf("node3passed\n");
|
|
||||||
|
|
||||||
TEST_ASSERT_NOT_NULL(testRoot->left->left);
|
TEST_ASSERT_NOT_NULL(testRoot->left->left);
|
||||||
TEST_ASSERT_EQUAL_UINT16(score4, testRoot->left->left->data);
|
TEST_ASSERT_EQUAL_UINT16(score4, testRoot->left->left->data);
|
||||||
// printf("node4passed\n");
|
|
||||||
|
|
||||||
TEST_ASSERT_NOT_NULL(testRoot->left->right);
|
TEST_ASSERT_NOT_NULL(testRoot->left->right);
|
||||||
TEST_ASSERT_EQUAL_UINT16(score5, testRoot->left->right->data);
|
TEST_ASSERT_EQUAL_UINT16(score5, testRoot->left->right->data);
|
||||||
// printf("node5passed\n");
|
|
||||||
|
|
||||||
TEST_ASSERT_NOT_NULL(testRoot->right->left);
|
TEST_ASSERT_NOT_NULL(testRoot->right->left);
|
||||||
TEST_ASSERT_EQUAL_UINT16(score6, testRoot->right->left->data);
|
TEST_ASSERT_EQUAL_UINT16(score6, testRoot->right->left->data);
|
||||||
// printf("node6passed\n");
|
|
||||||
|
|
||||||
TEST_ASSERT_NOT_NULL(testRoot->right->right);
|
TEST_ASSERT_NOT_NULL(testRoot->right->right);
|
||||||
TEST_ASSERT_EQUAL_UINT16(score7, testRoot->right->right->data);
|
TEST_ASSERT_EQUAL_UINT16(score7, testRoot->right->right->data);
|
||||||
// printf("node7passed\n");
|
|
||||||
|
|
||||||
// Adding Double
|
// Adding Double
|
||||||
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
testRoot = addToTree(testRoot, &score4, sizeof(int), compareIntEntries, NULL);
|
||||||
TEST_ASSERT_NOT_NULL(testRoot->left->left->left);
|
TEST_ASSERT_NOT_NULL(testRoot->left->left->left);
|
||||||
TEST_ASSERT_EQUAL_UINT16(score4, testRoot->left->left->left->data);
|
TEST_ASSERT_EQUAL_UINT16(score4, testRoot->left->left->left->data);
|
||||||
// printf("double passed\n");
|
|
||||||
|
|
||||||
// Trying to add Double while Doubles not Permitted
|
// 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_NULL(testRoot->right->right->left);
|
||||||
TEST_ASSERT_EQUAL_UINT16(1, testIsDouble);
|
TEST_ASSERT_EQUAL_UINT16(1, testIsDouble);
|
||||||
|
|
||||||
|
|
||||||
//clearTree(testRoot);
|
|
||||||
|
|
||||||
|
//clearTree(testRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user