at a state of not working

This commit is contained in:
Tobias Grampp 2025-12-04 16:18:24 +01:00
parent cbafb5f0f2
commit b7249a9c1c
3 changed files with 15 additions and 16 deletions

View File

@ -1,6 +1,9 @@
#include <string.h>
#include "stack.h"
#include "bintree.h"
#include <stdio.h>
StackNode *stackRoot = NULL;//Generates a new, empty stack for next tree data
//TODO: binären Suchbaum implementieren
/* * `addToTree`: fügt ein neues Element in den Baum ein (rekursiv),
@ -12,12 +15,17 @@
// 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");
strcpy(newNode->data, data);
printf("data pasted\n");
if(isDuplicate)
*isDuplicate = 0;
return newNode;
@ -47,26 +55,16 @@ 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)
{
StackNode *stackRoot = NULL;//Generates a new, empty stack
stackRoot = iterateThroughTree(root, stackRoot); //Fills the stack via the helping function iterateThroughTree
StackNode * tempBuffer = pop(stackRoot);
clearStack(stackRoot);
return tempBuffer;
}
//Function to aid nextTreeData
StackNode *iterateThroughTree(TreeNode *root, StackNode *stackRoot)
{
if(!root)
if(root)
{
return stackRoot;
stackRoot = push(root->data, stackRoot);
nextTreeData(root->left);
nextTreeData(root->right);
}
stackRoot = iterateThroughTree(root->left, stackRoot);
stackRoot = push(stackRoot, root->data);
stackRoot = iterateThroughTree(root->right, stackRoot);
return stackRoot;
}
// Releases all memory resources (including data copies).
void clearTree(TreeNode *root)
{

View File

@ -66,7 +66,9 @@ 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");
}
}

1
main.c
View File

@ -77,7 +77,6 @@ int main(int argc, char *argv[])
}
else
printf("Leider ist %u nicht korrekt. Richtig waere %u gewesen.\n", userInput, duplicate);
loadHighscores(highscorePath);
showHighscores();
saveHighscores(highscorePath);