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

Merge branch '6-add-pop-function' into 'main'

Resolve "Add pop function"

Closes #6

See merge request !16
parents e4bcf652 d93508e5
Branches
Tags
1 merge request!16Resolve "Add pop function"
*.o
main
\ No newline at end of file
......@@ -18,6 +18,19 @@ void stack_destroy(stack *s){
s->top = -1;
}
void stack_pop(stack *s, int *value){
if (stack_is_empty(*s)) {
return;
}
if (s->top == s->capacity/4){
s->capacity /= 2;
s->data = realloc(s->data, sizeof(int)*s->capacity);
}
*value = s->data[s->top];
s->top -= 1;
}
void stack_peek(stack s, int *value){
if (!stack_is_empty(s)) {
*value = s.data[s.top];
......@@ -51,4 +64,3 @@ int get_length(stack s)
{
return s.top + 1;
}
......@@ -11,6 +11,7 @@ void stack_init(stack *stack);
void stack_destroy(stack *s);
void stack_pop(stack *s, int *value);
void stack_peek(stack s, int *value);
void stack_clone(stack s, stack *clone);
int get_length(stack s);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment