generated from freudenreichan/info2Praktikum-DobleSpiel
less, but still some problems with socre saving
This commit is contained in:
parent
b7249a9c1c
commit
53f4716354
11
bintree.c
11
bintree.c
@ -15,28 +15,25 @@ StackNode *stackRoot = NULL;//Generates a new, empty stack for next tree data
|
|||||||
// if isDuplicate is NULL, otherwise ignores duplicates and sets isDuplicate to 1 (or to 0 if a new entry is added).
|
// if isDuplicate is NULL, otherwise ignores duplicates and sets isDuplicate to 1 (or to 0 if a new entry is added).
|
||||||
TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate)
|
TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate)
|
||||||
{
|
{
|
||||||
printf("Sind in add to tree. Root ist: %d\n", root);
|
|
||||||
if(!root)
|
if(!root)
|
||||||
{
|
{
|
||||||
//root = malloc(sizeof(TreeNode));
|
//root = malloc(sizeof(TreeNode));
|
||||||
printf("NULL detected\n");
|
|
||||||
TreeNode *newNode = malloc(sizeof(TreeNode));
|
TreeNode *newNode = malloc(sizeof(TreeNode));
|
||||||
printf("Node Allocated\n");
|
|
||||||
newNode->data = malloc(dataSize);
|
newNode->data = malloc(dataSize);
|
||||||
printf("data allcoated\n");
|
newNode->left = NULL;
|
||||||
|
newNode->right = NULL;
|
||||||
strcpy(newNode->data, data);
|
strcpy(newNode->data, data);
|
||||||
printf("data pasted\n");
|
|
||||||
if(isDuplicate)
|
if(isDuplicate)
|
||||||
*isDuplicate = 0;
|
*isDuplicate = 0;
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
if(compareFct(data, root->data) > 0)
|
if(compareFct(data, root->data) > 0)
|
||||||
{
|
{
|
||||||
root->right = addToTree(root->right, data, dataSize, compareFct, isDuplicate);
|
root->right = addToTree((root->right), data, dataSize, compareFct, isDuplicate);
|
||||||
}
|
}
|
||||||
else if(compareFct(data, root->data) < 0)
|
else if(compareFct(data, root->data) < 0)
|
||||||
{
|
{
|
||||||
root->left = addToTree(root->left, data, dataSize, compareFct, isDuplicate);
|
root->left = addToTree((root->left), data, dataSize, compareFct, isDuplicate);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -52,6 +52,7 @@ static int calculateScore(double timeInSeconds, unsigned int len)
|
|||||||
// Load highscores from file into memory.
|
// Load highscores from file into memory.
|
||||||
void loadHighscores(const char *path)
|
void loadHighscores(const char *path)
|
||||||
{
|
{
|
||||||
|
printf("pointer ist: %x", highscoreTree);
|
||||||
FILE *file = fopen(path, "r");
|
FILE *file = fopen(path, "r");
|
||||||
|
|
||||||
if(file != NULL)
|
if(file != NULL)
|
||||||
@ -66,9 +67,7 @@ void loadHighscores(const char *path)
|
|||||||
if(name != NULL && scoreStr != NULL)
|
if(name != NULL && scoreStr != NULL)
|
||||||
{
|
{
|
||||||
HighscoreEntry entry = createHighscoreEntry(name, strtol(scoreStr, NULL, 10));
|
HighscoreEntry entry = createHighscoreEntry(name, strtol(scoreStr, NULL, 10));
|
||||||
printf("Pre Tree");
|
|
||||||
highscoreTree = addToTree(highscoreTree, &entry, sizeof(entry), compareHighscoreEntries, NULL);
|
highscoreTree = addToTree(highscoreTree, &entry, sizeof(entry), compareHighscoreEntries, NULL);
|
||||||
printf("Post Tree");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,2 +1,10 @@
|
|||||||
Lukas;4985
|
Παhύ;0
|
||||||
player1;3999
|
Παhύ;0
|
||||||
|
Παhύ;0
|
||||||
|
Παhύ;0
|
||||||
|
Παhύ;0
|
||||||
|
Παhύ;0
|
||||||
|
Παhύ;0
|
||||||
|
Παhύ;0
|
||||||
|
Παhύ;0
|
||||||
|
Παhύ;0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user