Select Git revision
stack.c 379 B
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#define DEFAULT_CAPACITY 4
typedef struct _stack {
int *data;
int capacity;
int top;
} stack;
// depile
void stack_pop(stack *s, int *value){
assert(s->top>=0 && "Stcak is empty\n");
if (s->top == s->capacity/4){
s->capacity /= 2;
}
*value = s->data[s->top];
s->top -= 1;
}