bugfixingV1
This commit is contained in:
parent
ef6946fa0b
commit
d27b558ddc
17
bintree.c
17
bintree.c
@ -14,13 +14,14 @@ static TreeNode *createNode(const void *data, size_t dataSize)
|
|||||||
if (!newNode)
|
if (!newNode)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
newNode->data = malloc(dataSize);
|
newNode->data = malloc(dataSize); //hier kein malloc -> nur data pointer?
|
||||||
if (!newNode->data)
|
if (!newNode->data)
|
||||||
{
|
{
|
||||||
free(newNode);
|
free(newNode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
newNode->data = data;
|
//newNode->data = data;
|
||||||
|
memcpy(newNode->data, data, dataSize);
|
||||||
|
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
@ -125,12 +126,10 @@ void clearTree(TreeNode *root)
|
|||||||
// Returns the number of entries in the tree given by root.
|
// Returns the number of entries in the tree given by root.
|
||||||
unsigned int treeSize(const TreeNode* root)
|
unsigned int treeSize(const TreeNode* root)
|
||||||
{
|
{
|
||||||
unsigned int treeSize = 0;
|
if (root == NULL) {
|
||||||
TreeNode* data = nextTreeData(root);
|
return 0;
|
||||||
while (data != NULL)
|
|
||||||
{
|
|
||||||
treeSize++;
|
|
||||||
data = nextTreeData(NULL);
|
|
||||||
}
|
}
|
||||||
return treeSize;
|
|
||||||
|
return 1 + treeSize(root->left) + treeSize(root->right);
|
||||||
|
/// ich + alles links + alles rechts
|
||||||
}
|
}
|
||||||
@ -5,18 +5,19 @@
|
|||||||
|
|
||||||
typedef int (*CompareFctType)(const void *arg1, const void *arg2); //ganz zahlen
|
typedef int (*CompareFctType)(const void *arg1, const void *arg2); //ganz zahlen
|
||||||
|
|
||||||
void foo(void* ptr) {
|
/*void foo(void* ptr) {
|
||||||
unsigned int* casted_pointer = ptr;
|
unsigned int* casted_pointer = ptr;
|
||||||
unsigned int** a = &casted_pointer; //pointer pointer
|
unsigned int** a = &casted_pointer; //pointer pointer
|
||||||
unsigned int* b = casted_pointer; //pointer
|
unsigned int* b = casted_pointer; //pointer
|
||||||
unsigned int c = *casted_pointer; //wert
|
unsigned int c = *casted_pointer; //wert
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
typedef struct node
|
typedef struct nodeT
|
||||||
{
|
{
|
||||||
void *data;
|
void *data;
|
||||||
struct node *left;
|
struct nodeT *left;
|
||||||
struct node *right;
|
struct nodeT *right;
|
||||||
} TreeNode;
|
} TreeNode;
|
||||||
|
|
||||||
// Adds a copy of data's pointer destination to the tree using compareFct for ordering. Accepts duplicates
|
// Adds a copy of data's pointer destination to the tree using compareFct for ordering. Accepts duplicates
|
||||||
|
|||||||
BIN
highscore.o
Normal file
BIN
highscore.o
Normal file
Binary file not shown.
@ -1,5 +1,3 @@
|
|||||||
player2;17901
|
à«;1
|
||||||
player_name2;14920
|
;0
|
||||||
player2;14844
|
À«;0
|
||||||
player_name;6977
|
|
||||||
player1;3999
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include "numbers.h"
|
#include "numbers.h"
|
||||||
#include "bintree.h"
|
#include "bintree.h"
|
||||||
|
|
||||||
CompareFctType compareFct(const void *arg1, const void *arg2)
|
int compareFct(const void *arg1, const void *arg2)
|
||||||
{
|
{
|
||||||
const unsigned int *entry1 = arg1;
|
const unsigned int *entry1 = arg1;
|
||||||
const unsigned int *entry2 = arg2;
|
const unsigned int *entry2 = arg2;
|
||||||
@ -56,8 +56,8 @@ unsigned int *createNumbers(unsigned int len)
|
|||||||
|
|
||||||
clearTree(numbers);
|
clearTree(numbers);
|
||||||
|
|
||||||
int duplicatePosition1 = rand() % len;
|
unsigned int duplicatePosition1 = rand() % len;
|
||||||
int duplicatePosition2 = rand() % len;
|
unsigned int duplicatePosition2 = rand() % len;
|
||||||
|
|
||||||
while (duplicatePosition2 == duplicatePosition1)
|
while (duplicatePosition2 == duplicatePosition1)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user