Skip to content
Snippets Groups Projects

Resolve "Add peek function"

Merged narindra.rajohnso requested to merge 7-add-peek-function into main
All threads resolved!
Files
2
+ 8
3
#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
@@ -10,4 +9,10 @@ void stack_init(stack *s)
@@ -10,4 +9,10 @@ void stack_init(stack *s)
s->top = -1;
s->top = -1;
s->capacity = DEFAULT_CAPACITY;
s->capacity = DEFAULT_CAPACITY;
s->data = malloc(sizeof(int) * 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];
 
}
 
}
Loading