Compare commits

..

No commits in common. "96a97c07c9a71417cedc885ca55424bf5f49b96f" and "0575eac07efc435d9db3352cf6dbe6b9476973e0" have entirely different histories.

6 changed files with 30 additions and 45 deletions

4
.gitignore vendored
View File

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

View File

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

View File

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

27
stack.c
View File

@ -1,13 +1,5 @@
#include "stack.h"
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "stack.h"
/*typedef struct {
void *data;
struct StackNode *next;
} 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,
@ -68,18 +60,17 @@ 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.
void clearStack(StackNode **stack) void clearStack(StackNode *stack)
{ {
while (*stack != NULL) while (stack != NULL)
{ {
StackNode *next = (*stack)->next; StackNode *next = (stack)->next;
free(*stack); free(stack);
(*stack)->data = NULL; stack = next;
(*stack)->next = NULL; (stack)->data = NULL;
(*stack)->prev = NULL; (stack)->next = NULL;
(*stack) = next; (stack)->prev = NULL;
} }
} }

24
stack.h
View File

@ -1,23 +1,13 @@
#ifndef STACK_H #ifndef STACK_H
#define STACK_H #define STACK_H
/* A stack is a special type of queue which uses the LIFO (last in, first out) /* A stack is a special type of queue which uses the LIFO (last in, first out) principle.
principle. This means that with each new element all other elements are pushed This means that with each new element all other elements are pushed deeper into the stack.
deeper into the stack. The latest element is taken from the stack. */ The latest element is taken from the stack. */
#include <stdlib.h> #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 { typedef struct StackNode {
@ -32,14 +22,14 @@ 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);
// 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);
// Returns the data of the top element. // Returns the data of the top element.
void *top(StackNode *stack); void *top(StackNode *stack);
// Clears stack and releases all memory. // Clears stack and releases all memory.
void clearStack(StackNode **stack); void clearStack(StackNode *stack);
#endif #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]); //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); TEST_ASSERT_NULL(testStack);
} }