Anfänge von stack

This commit is contained in:
KohlerMaxi committed 2026-11-12 15:26:36 +01:00
1 parent c2cdde6707
commit b9e81dbbac
3 files changed
+54 -5

No files matched your search

+11 -2
View File
@@ -5,7 +5,10 @@
/* * `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. */
* `clearStack`: gibt den gesamten Speicher frei.
*/
// Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data)
@@ -13,6 +16,8 @@ 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)
@@ -20,14 +25,18 @@ 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)
{
}
}
+7 -3
View File
@@ -1,13 +1,17 @@
#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.
/* 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
//Erschaft den stack.
StackNode *create();
// Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data);
+36
View File
@@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
#include "unity/unity.h"
//Gebastelt von Maxi
/*Unit-Tests sollen:
Integer-Werte auf den Stack legen
Integer-Werte auf den Stack wieder entfernen
*/
//TODO Testcases einfügen
//void test_name(void){}
int main()
{
UNITY_BEGIN();
printf("============================\nStack tests\n============================\n");
RUN_TEST();
return UNITY_END();
}