9 Commits
Author SHA1 Message Date
Kristin 5e96ec050c test_stack mit & 2025-12-05 11:24:35 +01:00
Kristin f42a997683 clearstack mit ** 2025-12-05 11:12:30 +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
29 changed files with 187 additions and 123 deletions
+2 -61
View File
@@ -1,62 +1,3 @@
# ---> C
# Prerequisites
*.d
# Object files
doble_initial.exe
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
Startcode/doble_initial
Startcode/doble
Startcode/unitTests
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
# IDE folders
.vscode/
.idea/
# macOS
.DS_Store
*.exe
Binary file not shown.
-33
View File
@@ -1,33 +0,0 @@
#include <stdlib.h>
#include "stack.h"
//TODO: grundlegende Stackfunktionen implementieren:
/* * `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. */
// 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.)
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)
{
}
-25
View File
@@ -1,25 +0,0 @@
#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. */
#include <stdlib.h>
//TODO: passenden Datentyp als struct anlegen
// 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.)
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);
#endif
View File
View File
@@ -1 +1,2 @@
krisp;4986
player1;3999
View File
+10 -4
View File
@@ -35,15 +35,21 @@ $(program_obj_files): %.o: %.c
# --------------------------
# Unit Tests
# --------------------------
unitTests:
echo "needs to be implemented"
TEST_BIN = runTests
unitTests: stack.o test_stack.o
$(CC) $(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
# --------------------------
# Clean
# --------------------------
clean:
ifeq ($(OS),Windows_NT)
del /f *.o doble
else
rm -f *.o doble
else
del /f *.o doble
endif
View File
View File
+82
View File
@@ -0,0 +1,82 @@
#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,
* `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 *node = malloc(sizeof(StackNode));
if (node == NULL)
return NULL;
node->data = data;
node->next = NULL;
node->prev = NULL;
return node;
}
// Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data) {
StackNode *newNode = createNode(data);
if (newNode == NULL) {
return stack;
}
newNode->next = stack;
if (stack != NULL) {
stack->prev = newNode;
}
return newNode;
}
// 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;
StackNode *nextNode = stack->next;
if (nextNode != NULL) {
nextNode->prev = NULL;
}
free(stack);
stack = NULL;
return nextNode;
}
// Returns the data of the top element.
void *top(StackNode *stack) { return stack ? stack->data : NULL; }
// Clears stack and releases all memory.
void clearStack(StackNode **stack) {
while (*stack != NULL) {
StackNode *next = (*stack)->next;
free(*stack);
*stack = next;
}
}
+35
View File
@@ -0,0 +1,35 @@
#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. */
#include <stdlib.h>
// TODO: passenden Datentyp als struct anlegen
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);
// 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);
#endif
+57
View File
@@ -0,0 +1,57 @@
#include "unity.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stack.h"
void test_createNode(void) {
int testInt = 26;
StackNode *testNode = createNode(&testInt);
TEST_ASSERT_NOT_NULL(testNode);
TEST_ASSERT_EQUAL_PTR(&testInt, testNode->data);
TEST_ASSERT_NULL(testNode->next);
TEST_ASSERT_NULL(testNode->prev);
free(testNode);
}
void test_pushDataToStack(void) {}
void test_deleteTopElement(void) {}
void test_returnData(void) {}
void test_clearStack(void) {
int testInts[] = {1, 2, 3, 4, 5};
StackNode *stack = NULL;
for (int i = 0; i < 5; i++) {
stack = push(stack, &testInts[i]);
}
clearStack(&stack);
TEST_ASSERT_NULL(stack);
}
void setUp(void) {}
void tearDown(void) {}
int main(void) {
UNITY_BEGIN();
printf("------------------------stack test------------------------\n");
RUN_TEST(test_createNode);
RUN_TEST(test_pushDataToStack);
RUN_TEST(test_deleteTopElement);
RUN_TEST(test_returnData);
RUN_TEST(test_clearStack);
RUN_TEST(test_clearStack);
return UNITY_END();
}
View File
View File