less, but still some problems with socre saving

This commit is contained in:
Tobias Grampp 2025-12-04 16:54:33 +01:00
parent b7249a9c1c
commit 53f4716354
3 changed files with 15 additions and 11 deletions

View File

@ -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).
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)
{
//root = malloc(sizeof(TreeNode));
printf("NULL detected\n");
TreeNode *newNode = malloc(sizeof(TreeNode));
printf("Node Allocated\n");
newNode->data = malloc(dataSize);
printf("data allcoated\n");
newNode->left = NULL;
newNode->right = NULL;
strcpy(newNode->data, data);
printf("data pasted\n");
if(isDuplicate)
*isDuplicate = 0;
return newNode;
}
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)
{
root->left = addToTree(root->left, data, dataSize, compareFct, isDuplicate);
root->left = addToTree((root->left), data, dataSize, compareFct, isDuplicate);
}
else
{

View File

@ -52,6 +52,7 @@ static int calculateScore(double timeInSeconds, unsigned int len)
// Load highscores from file into memory.
void loadHighscores(const char *path)
{
printf("pointer ist: %x", highscoreTree);
FILE *file = fopen(path, "r");
if(file != NULL)
@ -66,9 +67,7 @@ void loadHighscores(const char *path)
if(name != NULL && scoreStr != NULL)
{
HighscoreEntry entry = createHighscoreEntry(name, strtol(scoreStr, NULL, 10));
printf("Pre Tree");
highscoreTree = addToTree(highscoreTree, &entry, sizeof(entry), compareHighscoreEntries, NULL);
printf("Post Tree");
}
}

View File

@ -1,2 +1,10 @@
Lukas;4985
player1;3999
Πα;0
Πα;0
Πα;0
Πα;0
Πα;0
Πα;0
Πα;0
Πα;0
Πα;0
Πα;0