From f10345b12df3efdbfd1d6cd08a37ac33fe1bd507 Mon Sep 17 00:00:00 2001
From: jonas <jonas.stirnemann@etu.hesge.ch>
Date: Mon, 6 Dec 2021 18:44:28 +0100
Subject: [PATCH] Added stack_clear function

---
 stack.c | 15 +++++++++++----
 stack.h |  5 +++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/stack.c b/stack.c
index 209089f..4e59e8f 100644
--- a/stack.c
+++ b/stack.c
@@ -1,7 +1,3 @@
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdio.h>
-
 #include "stack.h"
 
 
@@ -87,4 +83,15 @@ int get_length(stack s) {
 bool stack_is_empty(stack s)
 {
     return s.top == -1;
+}
+
+/**
+ * @brief Reset the stack's top to -1
+ *        New values will overwrite the old ones 
+ * 
+ * @param s
+ */
+void stack_clear(stack *s) 
+{
+    s->top = -1;
 }
\ No newline at end of file
diff --git a/stack.h b/stack.h
index 5aa60b4..371cb4d 100644
--- a/stack.h
+++ b/stack.h
@@ -1,3 +1,7 @@
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdio.h>
+
 #ifndef _STACK_H_
 #define _STACK_H_
 
@@ -17,6 +21,7 @@ void stack_peek(stack s, int *value);
 void stack_clone(stack s, stack *clone);
 int get_length(stack s);
 bool stack_is_empty(stack s);
+void stack_clear(stack *s) ;
 
 void stack_print(const stack s);
 
-- 
GitLab