From 6b2c9fc5cb24bb154d41aef0397762a7d773549e Mon Sep 17 00:00:00 2001 From: "richarda.tyarks" <richard-andre.tyarks@etu.hesge.ch> Date: Thu, 2 Dec 2021 21:23:10 +0100 Subject: [PATCH] add realloc in stack_push --- stack.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stack.c b/stack.c index 0555575..a2b1c52 100644 --- a/stack.c +++ b/stack.c @@ -1,4 +1,3 @@ -#include <stdio.h> #include <stdlib.h> #define DEFAULT_CAPACITY 4 @@ -18,6 +17,11 @@ void stack_destroy(stack *s) { void stack_push(stack *s, int value) { + if (s->top == s->capacity-1) + { + assert(s->data = realloc(s->capacity * 2 * sizeof(int))); + } + s->top++; s->data[s->top] = value; } -- GitLab