2025-12-08 14:00:19 +01:00

41 lines
930 B
C

#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
int main() {
StackNode *stack = NULL;
// Einige Integer dynamisch alloziieren
int *a = malloc(sizeof(int));
int *b = malloc(sizeof(int));
int *c = malloc(sizeof(int));
*a = 10; *b = 20; *c = 30;
stack = push(stack, a);
stack = push(stack, b);
stack = push(stack, c);
// Test top()
printf("Top = %d (expected 30)\n", *(int *)top(stack));
// pop()
stack = pop(stack); // removed 30
free(c); // data gehört Benutzer!
printf("Top = %d (expected 20)\n", *(int *)top(stack));
stack = pop(stack); free(b); // removed 20
stack = pop(stack); free(a); // removed 10
// stack should now be empty
if (stack == NULL) {
printf("Stack empty ok\n");
} else {
printf("Error: stack not empty!\n");
}
// Cleanup just in case
clearStack(stack);
return 0;
}