From 93cf851016a5ce5870daad6ef5f98efc00dcf508 Mon Sep 17 00:00:00 2001 From: "alec.schmidt" <alec.schmidt@etu.hesge.ch> Date: Thu, 25 Nov 2021 20:36:17 +0100 Subject: [PATCH] * Added `stack_init()` function * Added `DEFAULT_CAPACITY` constant --- stack.c | 12 ++++++++++++ stack.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/stack.c b/stack.c index 7380615..1813ff5 100644 --- a/stack.c +++ b/stack.c @@ -1 +1,13 @@ #include "stack.h" +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +#define DEFAULT_CAPACITY 4 + +void stack_init(stack *s) +{ + 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 9796be5..dfdc9a1 100644 --- a/stack.h +++ b/stack.h @@ -7,4 +7,6 @@ typedef struct _stack { int top; } stack; +void stack_init(stack *stack); + #endif -- GitLab