generated from freudenreichan/info2Praktikum-DobleSpiel
bintree fehlerbehebung und bintreetest erstellt
This commit is contained in:
parent
df7018f8f6
commit
33b370f0d2
46
bintree.c
46
bintree.c
@ -34,14 +34,16 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
|
||||
int cmp = compareFct(data, root->data);
|
||||
|
||||
if (cmp == 0){
|
||||
|
||||
if (isDuplicate != NULL) {
|
||||
*isDuplicate = 1;
|
||||
}
|
||||
/*
|
||||
if (isDuplicate == NULL){
|
||||
root->right = addToTree(root->right, data, dataSize, compareFct, NULL);
|
||||
return root;
|
||||
}*/
|
||||
|
||||
*isDuplicate = 1;
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@ -60,15 +62,41 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
|
||||
// push the top node and push all its left nodes.
|
||||
void *nextTreeData(TreeNode *root)
|
||||
{
|
||||
if (root != NULL){
|
||||
|
||||
|
||||
|
||||
|
||||
static StackNode *stack = NULL;
|
||||
static TreeNode* currentNode = NULL;
|
||||
void* result;
|
||||
|
||||
if(stack==NULL && root != NULL){
|
||||
currentNode = root;
|
||||
while(currentNode != NULL){
|
||||
stack = push(stack,currentNode);
|
||||
currentNode = currentNode->left;
|
||||
}
|
||||
}
|
||||
|
||||
if (stack == NULL)return NULL;
|
||||
|
||||
currentNode = top(stack);
|
||||
stack = pop(stack);
|
||||
|
||||
|
||||
result = currentNode->data;
|
||||
|
||||
if(currentNode->right != NULL){
|
||||
currentNode = currentNode->right;
|
||||
|
||||
while(currentNode != NULL){
|
||||
stack = push(stack,currentNode);
|
||||
currentNode = currentNode->left;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Releases all memory resources (including data copies).
|
||||
void clearTree(TreeNode *root)
|
||||
{
|
||||
@ -103,8 +131,8 @@ int compareFct(const void *a, const void *b){
|
||||
unsigned int A = *(unsigned int *)a;
|
||||
unsigned int B = *(unsigned int *)b;
|
||||
int result= 0;
|
||||
if(A>B)result = -1; //logik vertauscht?
|
||||
if(B>A)result = 1; //logik vertauscht?
|
||||
if(A>B)result = 1;
|
||||
if(B>A)result = -1;
|
||||
if(A==B)result = 0;
|
||||
|
||||
return result;
|
||||
|
||||
25
bintreeTests.c
Normal file
25
bintreeTests.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include "unity/unity.h"
|
||||
#include "bintree.h"
|
||||
|
||||
void setUp(void){}
|
||||
void tearDown(void){}
|
||||
|
||||
void TEST_BINTREE{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
UNITY_BEGIN();
|
||||
|
||||
printf("\n============================\nbintree tests\n============================\n");
|
||||
|
||||
//RUN_TEST();
|
||||
//RUN_TEST();
|
||||
//RUN_TEST();
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user