From 50386f6cd73eb33aa8d38504cb5e7f5702b84eba Mon Sep 17 00:00:00 2001
From: "narindra.rajohnso" <narindra-hasimanjaka-david.rajohnson@etu.hesge.ch>
Date: Thu, 25 Nov 2021 21:53:56 +0100
Subject: [PATCH] * Added stack_peek function to peek at the top of the stack.

---
 stack.c | 11 ++++++++---
 stack.h |  2 ++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/stack.c b/stack.c
index 1813ff5..2746918 100644
--- a/stack.c
+++ b/stack.c
@@ -1,7 +1,6 @@
-#include "stack.h"
-#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include "stack.h"
 
 #define DEFAULT_CAPACITY 4
 
@@ -10,4 +9,10 @@ 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
+}
+
+void stack_peek(stack s, int *value){
+    if (!stack_is_empty(s)) {
+        *value = s.data[s.top];
+    }
+}
diff --git a/stack.h b/stack.h
index dfdc9a1..8da80c2 100644
--- a/stack.h
+++ b/stack.h
@@ -9,4 +9,6 @@ typedef struct _stack {
 
 void stack_init(stack *stack);
 
+void stack_peek(stack s, int *value);
+
 #endif
-- 
GitLab