Skip to content

Instantly share code, notes, and snippets.

@fabianbaechli
Created April 22, 2025 14:15
Show Gist options
  • Save fabianbaechli/b726a348fe804845eb3762ff43642c51 to your computer and use it in GitHub Desktop.
Save fabianbaechli/b726a348fe804845eb3762ff43642c51 to your computer and use it in GitHub Desktop.
struct Stack {
int a[5];
int t;
};
struct Stack* create() {
struct Stack* s = malloc(sizeof(struct Stack));
s -> t = 0;
return s;
}
void dropStack(struct Stack* s) {
free(s);
}
// needs overflow checking
void push(Struct stack s, int val) {
s->a[s->t] = val;
s->t ++;
}
// needs underflow checking
int pop(struct Stack* s) {
int val = s->a[s->t];
s->t--;
return val;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment