feat(stack): introduce a stack ds, internally this uses a sll

This commit is contained in:
Squibid 2025-11-15 21:47:45 -05:00
parent 69dc1dcb45
commit 945343daa0
Signed by: squibid
GPG key ID: BECE5684D3C4005D
4 changed files with 127 additions and 0 deletions

22
test.c
View file

@ -1,3 +1,4 @@
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -76,4 +77,25 @@ main(int argc, char *argv[])
free(a);
);
test("stack",
char *a = "a";
char *b = "b";
char *c = "c";
ds_stack_t *stack = ds_stack_init();
it("pushes an item", ds_stack_push(stack, a) == 0);
it("pops an item", ds_stack_pop(stack) == a);
ds_stack_push(stack, b);
ds_stack_push(stack, c);
it("peeks ahead", ds_stack_peek(stack, 0) == c);
it("peeks past the stack", ds_stack_peek(stack, INT_MAX) == NULL);
ds_stack_pop(stack);
ds_stack_pop(stack);
free(stack);
);
}