feat(stack): introduce a stack ds, internally this uses a sll
This commit is contained in:
parent
69dc1dcb45
commit
945343daa0
4 changed files with 127 additions and 0 deletions
22
test.c
22
test.c
|
|
@ -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);
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue