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

* Added peek function

parents 32181909 6aab0548
No related branches found
No related tags found
1 merge request!5Resolve "Add peek function"
This commit is part of merge request !5. Comments created here will be created in the context of that merge request.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "stack.h" #include "stack.h"
#define DEFAULT_CAPACITY 4
void stack_init(stack *s)
{
s->top = -1;
s->capacity = DEFAULT_CAPACITY;
s->data = malloc(sizeof(int) * DEFAULT_CAPACITY);
}
void stack_peek(stack s, int *value){ void stack_peek(stack s, int *value){
if(stack_is_empty(s)){ if (!stack_is_empty(s)) {
*value=s.data[s.top]; *value = s.data[s.top];
} }
} }
...@@ -7,6 +7,8 @@ typedef struct _stack { ...@@ -7,6 +7,8 @@ typedef struct _stack {
int top; int top;
} stack; } stack;
void stack_init(stack *stack);
void stack_peek(stack s, int *value); 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