Compare commits

...

1 Commits
main ... Moritz

Author SHA1 Message Date
MoritzClub
41bc2078f5 Update 2025-12-11 13:01:31 +01:00
9 changed files with 186 additions and 0 deletions

18
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -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
}

24
.vscode/launch.json vendored Normal file
View File

@ -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
}
]
}
]
}

59
.vscode/settings.json vendored Normal file
View File

@ -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
}

View File

@ -8,10 +8,60 @@
* `treeSize`: zählt die Knoten im Baum (rekursiv), * `treeSize`: zählt die Knoten im Baum (rekursiv),
* `nextTreeData`: Traversierung mit Hilfe des zuvor implementierten Stacks. */ * `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 // 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). // 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)
{ {
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. // push the top node and push all its left nodes.
void *nextTreeData(TreeNode *root) void *nextTreeData(TreeNode *root)
{ {
if (root != NULL) {
clearStack(stack);
stack = NULL;
}
} }
// Releases all memory resources (including data copies). // Releases all memory resources (including data copies).
void clearTree(TreeNode *root) 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. // 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 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;
} }

BIN
doble_initial.exe Normal file

Binary file not shown.

View File

@ -1 +1,4 @@
Moritz1;9970
Moritz;9954
Moritz;4986
player1;3999 player1;3999

BIN
main.o Normal file

Binary file not shown.

View File

@ -9,6 +9,10 @@ The latest element is taken from the stack. */
//TODO: passenden Datentyp als struct anlegen //TODO: passenden Datentyp als struct anlegen
typedef struct{
void *data;
}StackNode;
// Pushes data as pointer onto the stack. // Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data); StackNode *push(StackNode *stack, void *data);

BIN
stack.o Normal file

Binary file not shown.