Skip to content
Snippets Groups Projects

Resolve "Add pop function"

Merged ines.maya requested to merge 6-add-pop-function into main
2 unresolved threads
2 files
+ 36
0
Compare changes
  • Side-by-side
  • Inline
Files
2
stack.c 0 → 100644
+ 27
0
#include "stack.h"
void stack_init(stack *s){
s->top = -1;
s->capacity = DEFAULT_CAPACITY;
s->data = malloc(sizeof(int) * DEFAULT_CAPACITY);
}
bool stack_is_empty(stack s){
return s.top == -1;
}
void stack_peek(stack s, int *value){
if (!stack_is_empty(s)) {
*value = s.data[s.top];
}
}
// depile
void stack_pop(stack *s, int *val){
if (stack_is_empty(*s)){
return;
}
*val = s->data[s->top];
s->top -= 1;
printf("pop : %d, top : %d\n", s->data[s->top],s->top);
}
Loading