Skip to content
Snippets Groups Projects
Commit 94a4d62f authored by orestis.malaspin's avatar orestis.malaspin
Browse files

Merge branch '7-add-peek-function' into 'main'

Resolve "Add peek function"

Closes #7

See merge request !5
parents 6aab0548 50386f6c
Branches
No related tags found
1 merge request!5Resolve "Add peek function"
#include "stack.h"
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "stack.h"
#define DEFAULT_CAPACITY 4 #define DEFAULT_CAPACITY 4
...@@ -11,3 +10,9 @@ void stack_init(stack *s) ...@@ -11,3 +10,9 @@ void stack_init(stack *s)
s->capacity = DEFAULT_CAPACITY; s->capacity = DEFAULT_CAPACITY;
s->data = malloc(sizeof(int) * DEFAULT_CAPACITY); s->data = malloc(sizeof(int) * DEFAULT_CAPACITY);
} }
void stack_peek(stack s, int *value){
if (!stack_is_empty(s)) {
*value = s.data[s.top];
}
}
...@@ -9,4 +9,6 @@ typedef struct _stack { ...@@ -9,4 +9,6 @@ typedef struct _stack {
void stack_init(stack *stack); void stack_init(stack *stack);
void stack_peek(stack s, int *value);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment