Merge remote-tracking branch 'origin/RMax' into tobi_experimental

This commit is contained in:
Tobias Kachel 2025-12-05 11:16:21 +01:00
commit 382c36b1b4
11 changed files with 156 additions and 48 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": "c:/Users/Max-R/I2Pr/info2Praktikum-DobleSpiel",
"program": "c:/Users/Max-R/I2Pr/info2Praktikum-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
}

BIN
doble_initial.exe Normal file

Binary file not shown.

View File

@ -35,7 +35,7 @@ $(program_obj_files): %.o: %.c
# --------------------------
# Unit Tests
# --------------------------
unitTests:
TEST_BIN = runTests
unitTests: stack.o test_stack.o

BIN
runTests.exe Normal file

Binary file not shown.

39
stack.c
View File

@ -10,15 +10,13 @@
} StackNode;*/
// TODO: grundlegende Stackfunktionen implementieren:
/* `push`: legt ein Element oben auf den Stack,
/* * `push`: legt ein Element oben auf den Stack,
* `pop`: entfernt das oberste Element,
* `top`: liefert das oberste Element zurück,
* `clearStack`: gibt den gesamten Speicher frei. */
// [A] -> [B] -> [C] -> NULL
// head -> stack.next
StackNode *createNode(void *data) {
StackNode *createNode(void *data)
{
StackNode *node =
malloc(sizeof(StackNode)); // Speicher reservieren, Speicherplatz für das
@ -34,12 +32,13 @@ StackNode *createNode(void *data) {
}
// Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data) {
StackNode *push(StackNode *stack, void *data)
{
StackNode *newNode = createNode(data); // Speicher für neuen Knoten
// reservieren
if (newNode == NULL) { // wenn Speicher nicht reserviert werden konnte, wird
if (newNode == NULL)
{ // wenn Speicher nicht reserviert werden konnte, wird
// stack unverändert zurückgegeben
return stack;
}
@ -49,10 +48,10 @@ StackNode *push(StackNode *stack, void *data) {
return newNode; // Zeiger auf neuen Speicherbereich zurückgeben
}
// Deletes the top element of the stack (latest added element) and releases its
// memory. (Pointer to data has to be freed by caller.)
StackNode *pop(StackNode *stack) {
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
// freed by caller.)
StackNode *pop(StackNode *stack)
{
if (stack == NULL)
return NULL;
@ -69,18 +68,16 @@ StackNode *pop(StackNode *stack) {
void *top(StackNode *stack) { return stack != NULL ? stack->data : NULL; }
// Clears stack and releases all memory.
void clearStack(StackNode *stack) {
while (stack != NULL) {
void clearStack(StackNode *stack)
{
while (stack != NULL)
{
StackNode *next = stack->next;
stack->data = NULL;
stack->prev = NULL;
stack->next = NULL;
free(stack);
stack = next;
stack->data = NULL;
stack->next = NULL;
stack->prev = NULL;
}
return NULL;
}

10
stack.h
View File

@ -19,6 +19,16 @@ typedef struct StackNode {
StackNode *createNode(void *data);
typedef struct StackNode {
void *data;
struct StackNode *next;
struct StackNode *prev;
} StackNode;
StackNode *createNode(void *data);
// Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data);

BIN
stack.o Normal file

Binary file not shown.

BIN
test_stack.o Normal file

Binary file not shown.