Skip to content
Snippets Groups Projects
Commit 50386f6c authored by narindra.rajohnso's avatar narindra.rajohnso Committed by orestis.malaspin
Browse files

* Added stack_peek function to peek at the top of the stack.

parent 6aab0548
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