libflint/src/stack.c

26 lines
556 B
C
Raw Normal View History

2021-02-01 22:06:37 +00:00
#include "stack.h"
2021-02-01 22:27:01 +00:00
void stack_init(Stack* stack, void (*destroy)(void* data)) {
2021-02-01 22:06:37 +00:00
ll_init(stack, destroy);
}
2021-02-01 22:27:01 +00:00
void stack_destroy(Stack* stack) {
2021-02-01 22:06:37 +00:00
ll_destroy(stack);
}
2021-02-01 22:27:01 +00:00
int stack_push(Stack* stack, void *data) {
2021-02-01 22:06:37 +00:00
if (stack->size == 0) {
return ll_ins_next(stack, NULL, data);
} else {
return ll_ins_next(stack, stack->tail, data);
}
}
2021-02-01 22:27:01 +00:00
void *stack_peek(Stack *stack) {
2021-02-01 22:06:37 +00:00
return stack->tail == NULL ? NULL : stack->tail->data;
}
2021-02-01 22:27:01 +00:00
int stack_pop(Stack *stack, void **data) {
2021-02-01 22:06:37 +00:00
return ll_remove(stack, stack->tail, data);
}