#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

#define INIT_STACK_SIZE 10
#define INC_STACK_SIZE 5

typedef struct
{
    int *data;
    size_t size;
    size_t cur;
} MyStack;


MyStack *myStackCreate()
{
    MyStack *s = malloc(sizeof(MyStack));
    s->data = malloc(sizeof(int) * INIT_STACK_SIZE);
    s->size = INIT_STACK_SIZE;
    s->cur = 0;
    return s;
}

void myStackPush(MyStack *obj, int x)
{
    if (obj->cur == obj->size)
    {
        obj->data = realloc(obj->data, sizeof(int) * (obj->size + INC_STACK_SIZE));
        obj->size += INC_STACK_SIZE;
    }

    obj->data[obj->cur] = x;
    obj->cur++;
}

int myStackPop(MyStack *obj)
{
    return obj->data[--obj->cur];
}

int myStackTop(MyStack *obj)
{
    return obj->data[obj->cur - 1];
}

bool myStackEmpty(MyStack *obj)
{
    return obj->cur == 0;
}

void myStackFree(MyStack *obj)
{
    free(obj->data);
    free(obj);
}

int main()
{
    MyStack *s = myStackCreate();
    myStackPush(s, 1);
    myStackPush(s, 2);
    assert(myStackTop(s) == 2);
    assert(myStackPop(s) == 2);
    assert(myStackEmpty(s) == false);

    return 0;
}
