Implementation and improvement test_stack.c

This commit is contained in:
Henrik Batz committed 2026-11-19 10:32:33 +01:00
1 parent 88d97f3b67
commit 1fae9e13d8
4 files changed
+165 -5

No files matched your search

+4 -4
View File
@@ -2,7 +2,7 @@
#include <stdlib.h>
StackNode *push(StackNode *stack, void *data) {
if (data == NULL)
if (data == NULL) //Das wird so gut wie immer getestet
return stack;
StackNode *newnode = malloc(sizeof(StackNode));
@@ -10,7 +10,7 @@ StackNode *push(StackNode *stack, void *data) {
return stack;
newnode->data = data;
newnode->next = stack;
newnode->next = stack; // Um Data was das neue Top ist mit der Kette zu verbinden
return newnode;
}
@@ -19,7 +19,7 @@ StackNode *pop(StackNode *stack) {
if (stack == NULL)
return stack;
StackNode *newtop = stack->next;
StackNode *newtop = stack->next; //speichert das nächste und löscht das oberste, speichert dann da "nächste" als oberstes
free(stack);
return newtop;
}
@@ -33,6 +33,6 @@ void *top(StackNode *stack) {
void clearStack(StackNode *stack) {
while (stack != NULL) {
stack = pop(stack); // pop returnt newtop;
stack = pop(stack); // pop returnt newtop und man springt immer weiter in der verkettung
}
}