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
Tags
1 merge request!5Resolve "Add peek function"
#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];
}
}
......@@ -9,4 +9,6 @@ typedef struct _stack {
void stack_init(stack *stack);
void stack_peek(stack s, int *value);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment