diff --git a/stack.c b/stack.c new file mode 100644 index 0000000000000000000000000000000000000000..834f1c4173f65342b10a3692b79e3507f6a0b954 --- /dev/null +++ b/stack.c @@ -0,0 +1,14 @@ +#include "stack.h" +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +#define DEFAULT_CAPACITY 4 + +void stack_init(stack *s) +{ + assert(s->data!=NULL && "Error : stack already in memory"); + s->top = -1; + s->capacity = DEFAULT_CAPACITY; + s->data = malloc(sizeof(int) * DEFAULT_CAPACITY); +} \ No newline at end of file diff --git a/stack.h b/stack.h index 9796be5f47ab539a622deaa3bf8b563157b7c7ab..dfdc9a1d8afe4525ad0ae59af873be50a78d2998 100644 --- a/stack.h +++ b/stack.h @@ -7,4 +7,6 @@ typedef struct _stack { int top; } stack; +void stack_init(stack *stack); + #endif