16 Commits
Author SHA1 Message Date
Max-R 96a97c07c9 Merge remote-tracking branch 'origin/tobi_experimental' into RMax 2025-12-05 12:05:01 +01:00
kachelto100370 74fdcf500f stack.c test laufen alle 2025-12-05 11:54:23 +01:00
Max-R 0575eac07e immer noch ohne clearstak 2025-12-05 11:47:36 +01:00
kachelto100370 382c36b1b4 Merge remote-tracking branch 'origin/RMax' into tobi_experimental 2025-12-05 11:16:21 +01:00
kachelto100370 81de4b3d36 arbeiten an stack.c 2025-12-05 11:13:27 +01:00
Max-R 09426ae40a tests bis auf clearstack laufen 2025-12-05 11:10:20 +01:00
Max-R 9443171664 create node 2025-12-05 11:04:09 +01:00
Max-R b28deeaafb mhm 2025-12-05 10:53:03 +01:00
Max-R 4bb0d7516e stak.c 2025-12-05 10:48:10 +01:00
Max-R ddd4132e1f erste tests stack.c 2025-12-05 10:41:30 +01:00
kachelto100370 624a7d8b41 slight changes to stackNode struct, void func, etc 2025-12-05 10:41:08 +01:00
kachelto100370 73ebc36c05 Merge branch 'KrispTobi' into tobi_experimental 2025-12-05 10:31:47 +01:00
Max-R e7423f0a20 stack.c 2025-12-05 10:26:10 +01:00
Max-R 7051134256 stack.h 2025-12-05 10:21:00 +01:00
Max-R 735195460c mein Branch 2025-12-02 10:44:15 +01:00
kachelto100370 ecb5f360e3 add highscore to gitignore 2025-12-02 10:35:34 +01:00
11 changed files with 163 additions and 46 deletions
+18
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
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
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
View File
Binary file not shown.
+4 -3
View File
@@ -1,5 +1,6 @@
CC = gcc CC = gcc
FLAGS = -g -Wall -lm FLAGS = -g -Wall -lm
ASAN_FLAGS = -fsanitize=address
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
include makefile_windows.variables include makefile_windows.variables
@@ -35,11 +36,11 @@ $(program_obj_files): %.o: %.c
# -------------------------- # --------------------------
# Unit Tests # Unit Tests
# -------------------------- # --------------------------
unitTests:
TEST_BIN = runTests TEST_BIN = runTests
unitTests: stack.o test_stack.o unitTests: stack.o test_stack.o
$(CC) $(FLAGS) -I$(unityfolder) -o $(TEST_BIN) stack.o test_stack.o $(unityfolder)/unity.c $(CC) $(FLAGS) $(ASAN_FLAGS) -I$(unityfolder) -o $(TEST_BIN) stack.o test_stack.o $(unityfolder)/unity.c
test_stack.o: test_stack.c test_stack.o: test_stack.c
$(CC) $(FLAGS) -I$(unityfolder) -c test_stack.c -o test_stack.o $(CC) $(FLAGS) -I$(unityfolder) -c test_stack.c -o test_stack.o
@@ -51,5 +52,5 @@ clean:
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
rm -f *.o doble rm -f *.o doble
else else
del /f *.o doble rm -f *.o doble
endif endif
BIN
View File
Binary file not shown.
+21 -18
View File
@@ -10,15 +10,13 @@
} StackNode;*/ } StackNode;*/
// TODO: grundlegende Stackfunktionen implementieren: // 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, * `pop`: entfernt das oberste Element,
* `top`: liefert das oberste Element zurück, * `top`: liefert das oberste Element zurück,
* `clearStack`: gibt den gesamten Speicher frei. */ * `clearStack`: gibt den gesamten Speicher frei. */
// [A] -> [B] -> [C] -> NULL StackNode *createNode(void *data)
// head -> stack.next {
StackNode *createNode(void *data) {
StackNode *node = StackNode *node =
malloc(sizeof(StackNode)); // Speicher reservieren, Speicherplatz für das malloc(sizeof(StackNode)); // Speicher reservieren, Speicherplatz für das
@@ -34,12 +32,13 @@ StackNode *createNode(void *data) {
} }
// 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)
{
StackNode *newNode = createNode(data); // Speicher für neuen Knoten StackNode *newNode = createNode(data); // Speicher für neuen Knoten
// reservieren // 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 // stack unverändert zurückgegeben
return stack; return stack;
} }
@@ -49,10 +48,10 @@ StackNode *push(StackNode *stack, void *data) {
return newNode; // Zeiger auf neuen Speicherbereich zurückgeben return newNode; // Zeiger auf neuen Speicherbereich zurückgeben
} }
// Deletes the top element of the stack (latest added element) and releases its // Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
// memory. (Pointer to data has to be freed by caller.) // freed by caller.)
StackNode *pop(StackNode *stack) { StackNode *pop(StackNode *stack)
{
if (stack == NULL) if (stack == NULL)
return NULL; return NULL;
@@ -69,14 +68,18 @@ StackNode *pop(StackNode *stack) {
void *top(StackNode *stack) { return stack != NULL ? stack->data : NULL; } void *top(StackNode *stack) { return stack != NULL ? stack->data : NULL; }
// Clears stack and releases all memory. // Clears stack and releases all memory.
StackNode *clearStack(StackNode *stack) { void clearStack(StackNode **stack)
{
while (*stack != NULL)
{
while (stack != NULL) { StackNode *next = (*stack)->next;
free(*stack);
(*stack)->data = NULL;
(*stack)->next = NULL;
(*stack)->prev = NULL;
(*stack) = next;
StackNode *next = stack->next;
free(stack);
stack = next;
} }
return NULL;
} }
+12 -1
View File
@@ -13,6 +13,17 @@ typedef struct StackNode {
void *data; void *data;
struct StackNode *next; struct StackNode *next;
struct StackNode *prev;
} StackNode;
StackNode *createNode(void *data);
typedef struct StackNode {
void *data;
struct StackNode *next;
struct StackNode *prev;
} StackNode; } StackNode;
@@ -29,6 +40,6 @@ StackNode *pop(StackNode *stack);
void *top(StackNode *stack); void *top(StackNode *stack);
// Clears stack and releases all memory. // Clears stack and releases all memory.
StackNode *clearStack(StackNode *stack); void clearStack(StackNode **stack);
#endif #endif
BIN
View File
Binary file not shown.
+2 -1
View File
@@ -35,8 +35,9 @@ void test_clearStack(void) {
testStack = push(testStack, &testInts[i]); testStack = push(testStack, &testInts[i]);
} }
//printf("testints: %d,%d,%d,%d,%d",testInts[0],testInts[1],testInts[2],testInts[3],testInts[4]);
testStack = clearStack(testStack); clearStack(&testStack);
TEST_ASSERT_NULL(testStack); TEST_ASSERT_NULL(testStack);
} }
BIN
View File
Binary file not shown.