BCI-base/stack.c

41 lines
647 B
C
Raw Normal View History

2018-09-26 15:50:12 +00:00
#include <stdlib.h>
#include "stack.h"
char bci_stack_t_push(bci_stack_t * stack, uint16_t value)
{
bci_stack_t node = malloc(sizeof(struct bci_stack_s));
if(!node)
{
return 1;
}
node->next = *stack;
node->value = value;
2018-09-26 16:22:36 +00:00
*stack = node;
2018-09-26 15:50:12 +00:00
return 0;
}
char bci_stack_t_pop(bci_stack_t * stack, uint16_t * result)
{
2018-09-26 16:22:36 +00:00
bci_stack_t this_node;
2018-09-26 15:50:12 +00:00
if(!*stack)
{
return 1;
}
2018-09-26 16:22:36 +00:00
this_node = *stack;
*result = this_node->value;
*stack = this_node->next;
free(this_node);
2018-09-26 15:50:12 +00:00
return 0;
}
2018-09-26 16:22:36 +00:00
void bci_stack_t_del(bci_stack_t * stack)
{
bci_stack_t this_node;
while(*stack)
{
this_node = *stack;
*stack = this_node->next;
free(this_node);
}
}