diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..cb8d469 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "C:/ProgramData/mingw64/mingw64/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..209cd35 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "e:/Informatik/Drittes Projekt/DobleSpiel", + "program": "e:/Informatik/Drittes Projekt/DobleSpiel/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bb879da --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/bintree.c b/bintree.c index 5cf82a9..b1889f0 100644 --- a/bintree.c +++ b/bintree.c @@ -8,10 +8,60 @@ * `treeSize`: zählt die Knoten im Baum (rekursiv), * `nextTreeData`: Traversierung mit Hilfe des zuvor implementierten Stacks. */ + + static StackNode *stack = NULL; + +TreeNode* createNode (const void* data, size_t dataSize){ + + TreeNode* newNode = (TreeNode*)malloc(sizeof(TreeNode)); + if (newNode == NULL){ + // Fehlerbehandlung + return NULL; + } + + newNode->data = malloc(dataSize); + if(newNode->data == NULL){ + free(newNode); // newNode freigeben + return NULL; + } + + memcpy (newNode->data, data, dataSize); + + newNode->left = NULL; + newNode->right = NULL; + return newNode; +} + // Adds a copy of data's pointer destination to the tree using compareFct for ordering. Accepts duplicates // 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) { + if (root == NULL) + { + TreeNode *newNode = createNode(data,dataSize); + if (isDuplicate != NULL) + *isDuplicate = 0; + + return newNode; + } + if (compareFct(root->data, data)==0) + { + if (isDuplicate != NULL) { + *isDuplicate=1; + return root; + } + TreeNode *newNode = createNode(data,dataSize); + return newNode; + } + else if (compareFct(root->data, data)>0) + { + root->left = addToTree(root->left, data, dataSize, compareFct, isDuplicate); + } + else if (compareFct(root->data, data)<0) + { + root->right= addToTree(root->right, data, dataSize, compareFct, isDuplicate); + } + return root; } @@ -20,17 +70,45 @@ 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) { + clearStack(stack); + stack = NULL; + } } // Releases all memory resources (including data copies). void clearTree(TreeNode *root) { + if (root != NULL) { + if (root->left != NULL) { + clearTree(root->left); + } + if (root->right != NULL) { + clearTree(root->right); + } + free(root->data); + free(root); + } } // Returns the number of entries in the tree given by root. unsigned int treeSize(const TreeNode *root) { + unsigned int size = 0; + if (root == NULL) { + return 0; + } + + if (root->left != NULL) + { + size += treeSize(root->left); + } + if (root->right != NULL) + { + size += treeSize(root->right); + } + return size+1; } \ No newline at end of file diff --git a/doble_initial.exe b/doble_initial.exe new file mode 100644 index 0000000..c56ffd8 Binary files /dev/null and b/doble_initial.exe differ diff --git a/highscores.txt b/highscores.txt index 4edd5a7..1cf0460 100644 --- a/highscores.txt +++ b/highscores.txt @@ -1 +1,4 @@ +Moritz1;9970 +Moritz;9954 +Moritz;4986 player1;3999 diff --git a/main.o b/main.o new file mode 100644 index 0000000..a5219de Binary files /dev/null and b/main.o differ diff --git a/stack.h b/stack.h index f7d542d..0465503 100644 --- a/stack.h +++ b/stack.h @@ -9,6 +9,10 @@ The latest element is taken from the stack. */ //TODO: passenden Datentyp als struct anlegen +typedef struct{ + void *data; +}StackNode; + // Pushes data as pointer onto the stack. StackNode *push(StackNode *stack, void *data); diff --git a/stack.o b/stack.o new file mode 100644 index 0000000..7954125 Binary files /dev/null and b/stack.o differ