Compare commits

...

13 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
74fdcf500f stack.c test laufen alle 2025-12-05 11:54:23 +01:00
382c36b1b4 Merge remote-tracking branch 'origin/RMax' into tobi_experimental 2025-12-05 11:16:21 +01:00
81de4b3d36 arbeiten an stack.c 2025-12-05 11:13:27 +01:00
624a7d8b41 slight changes to stackNode struct, void func, etc 2025-12-05 10:41:08 +01:00
73ebc36c05 Merge branch 'KrispTobi' into tobi_experimental 2025-12-05 10:31:47 +01:00
Kristin
8b44089f23 Remove object files 2025-12-05 10:25:10 +01:00
Kristin
654fb615a2 Remove object files 2025-12-05 10:24:32 +01:00
Kristin
422ac38d54 gitignore 2025-12-05 10:21:33 +01:00
Kristin
90612e4d04 stack.c 2025-12-05 10:20:17 +01:00
Kristin
17f4155891 stack.c 2025-12-05 10:08:55 +01:00
Kristin
a002901e2f highscore.txt zu gitignore 2025-12-02 10:40:28 +01:00
Kristin
55b25a227b makefile 2025-12-02 10:32:52 +01:00
6 changed files with 45 additions and 30 deletions

4
.gitignore vendored
View File

@ -1 +1,3 @@
highscores.txt
doble_initial.exe
*.o
*.exe

View File

@ -1,9 +1,2 @@
Max02.12;19860
max;19374
Max02.12;11910
kristin;9935
Max02.12;7966
player_name;7961
max;5989
Max02.12;4988
krisp;4986
player1;3999

View File

@ -1,5 +1,6 @@
CC = gcc
FLAGS = -g -Wall -lm
ASAN_FLAGS = -fsanitize=address
ifeq ($(OS),Windows_NT)
include makefile_windows.variables
@ -29,7 +30,7 @@ program_obj_files = stack.o bintree.o numbers.o timer.o highscore.o
doble : main.o $(program_obj_files)
$(CC) $(FLAGS) $^ -o doble
$(program_obj_filesobj_files): %.o: %.c
$(program_obj_files): %.o: %.c
$(CC) -c $(FLAGS) $^ -o $@
# --------------------------
@ -39,7 +40,7 @@ unitTests:
TEST_BIN = runTests
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
$(CC) $(FLAGS) -I$(unityfolder) -c test_stack.c -o test_stack.o
@ -49,7 +50,7 @@ test_stack.o: test_stack.c
# --------------------------
clean:
ifeq ($(OS),Windows_NT)
del /f *.o doble
rm -f *.o doble
else
rm -f *.o doble
endif

27
stack.c
View File

@ -1,5 +1,13 @@
#include <stdlib.h>
#include "stack.h"
#include <stdio.h>
#include <stdlib.h>
/*typedef struct {
void *data;
struct StackNode *next;
} StackNode;*/
// TODO: grundlegende Stackfunktionen implementieren:
/* * `push`: legt ein Element oben auf den Stack,
@ -60,17 +68,18 @@ StackNode *pop(StackNode *stack)
void *top(StackNode *stack) { return stack != NULL ? stack->data : NULL; }
// Clears stack and releases all memory.
void clearStack(StackNode *stack)
void clearStack(StackNode **stack)
{
while (stack != NULL)
while (*stack != NULL)
{
StackNode *next = (stack)->next;
free(stack);
stack = next;
(stack)->data = NULL;
(stack)->next = NULL;
(stack)->prev = NULL;
StackNode *next = (*stack)->next;
free(*stack);
(*stack)->data = NULL;
(*stack)->next = NULL;
(*stack)->prev = NULL;
(*stack) = next;
}
}

24
stack.h
View File

@ -1,13 +1,23 @@
#ifndef STACK_H
#define STACK_H
/* A stack is a special type of queue which uses the LIFO (last in, first out) principle.
This means that with each new element all other elements are pushed deeper into the stack.
The latest element is taken from the stack. */
/* A stack is a special type of queue which uses the LIFO (last in, first out)
principle. This means that with each new element all other elements are pushed
deeper into the stack. The latest element is taken from the stack. */
#include <stdlib.h>
//TODO: passenden Datentyp als struct anlegen
// TODO: passenden Datentyp als struct anlegen
typedef struct StackNode {
void *data;
struct StackNode *next;
struct StackNode *prev;
} StackNode;
StackNode *createNode(void *data);
typedef struct StackNode {
@ -22,14 +32,14 @@ StackNode *createNode(void *data);
// Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data);
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
// freed by caller.)
// 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);
// Returns the data of the top element.
void *top(StackNode *stack);
// Clears stack and releases all memory.
void clearStack(StackNode *stack);
void clearStack(StackNode **stack);
#endif

View File

@ -37,7 +37,7 @@ void test_clearStack(void) {
}
//printf("testints: %d,%d,%d,%d,%d",testInts[0],testInts[1],testInts[2],testInts[3],testInts[4]);
clearStack(testStack);
clearStack(&testStack);
TEST_ASSERT_NULL(testStack);
}
@ -57,4 +57,4 @@ int main(void) {
RUN_TEST(test_clearStack);
return UNITY_END();
}
}