Created
April 22, 2025 14:15
-
-
Save fabianbaechli/b726a348fe804845eb3762ff43642c51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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