Skip to content
Snippets Groups Projects

add function stack_push

Merged richarda.tyarks requested to merge 5-add-push-function into main
2 unresolved threads
1 file
+ 5
1
Compare changes
  • Side-by-side
  • Inline
+ 5
1
#include <stdio.h>
#include <stdlib.h>
#define DEFAULT_CAPACITY 4
@@ -18,6 +17,11 @@ void stack_destroy(stack *s) {
void stack_push(stack *s, int value)
{
if (s->top == s->capacity-1)
{
assert(s->data = realloc(s->capacity * 2 * sizeof(int)));
}
s->top++;
s->data[s->top] = value;
}
Loading