Skip to content
Snippets Groups Projects
Commit 6b2c9fc5 authored by richarda.tyarks's avatar richarda.tyarks
Browse files

add realloc in stack_push

parent 4ad268aa
No related branches found
No related tags found
1 merge request!7add function stack_push
#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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment