diff --git a/stack.c b/stack.c index 1813ff5cc17b36696b9dfd7428b8bf61d280b32e..27469186a0c3fb480eb73d281b64eac8d52ed6bd 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 dfdc9a1d8afe4525ad0ae59af873be50a78d2998..8da80c2f2fff5493b622780eb35d4157b1362621 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