41 lines
647 B
C
41 lines
647 B
C
#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;
|
|
*stack = node;
|
|
return 0;
|
|
}
|
|
char bci_stack_t_pop(bci_stack_t * stack, uint16_t * result)
|
|
{
|
|
bci_stack_t this_node;
|
|
if(!*stack)
|
|
{
|
|
return 1;
|
|
}
|
|
this_node = *stack;
|
|
*result = this_node->value;
|
|
*stack = this_node->next;
|
|
free(this_node);
|
|
return 0;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|