diff --git a/README.md b/README.md index 229684660ee3f291ddf813fa8a26e1ea75125c45..d3df88c50ac5febcacfd029a209a028f0f0a3f2e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # stack +# ohayo onii chan ! diff --git a/stack.c b/stack.c new file mode 100644 index 0000000000000000000000000000000000000000..85a71262375e5e8a531b5478650e233d9745c1ab --- /dev/null +++ b/stack.c @@ -0,0 +1,12 @@ +#include "stack.h" + +void stack_push(stack *s, int val) +{ + if (s->top == s->capacity-1) + { + assert(s->data = realloc(s->capacity * 2 * sizeof(int)) && "Error : realloc failed"); + } + + s->top++; + s->data[s->top] = val; +} \ No newline at end of file diff --git a/stack.h b/stack.h index 9796be5f47ab539a622deaa3bf8b563157b7c7ab..4f6289e666647051f010d411c45966903869bc4b 100644 --- a/stack.h +++ b/stack.h @@ -1,10 +1,12 @@ #ifndef _STACK_H_ #define _STACK_H_ + typedef struct _stack { int *data; int capacity; int top; } stack; +void stack_push(stack *s, int val); #endif