Need help with Error: store to address 0x0000015cc998 with insufficient space for an object of type 'struct minStack *'


  • 0
    M

    I am getting the following error:
    Line 22: store to address 0x0000015cc998 with insufficient space for an object of type 'struct minStack *'

    I have pasted my C code below. Suggestions?

    typedef struct minStack{
    int data;
    int min;
    struct minStack *next;
    } MinStack;

    /** initialize your data structure here. /
    MinStack
    minStackCreate(int maxSize) {
    MinStack *obj = NULL;
    return obj;
    }

    void minStackPush(MinStack* obj, int x) {
    MinStack *p1 = (MinStack *)malloc(sizeof(MinStack *));
    if(obj == NULL)
    p1->min = x;
    else if(obj->min > x)
    p1->min = x;
    else
    p1->min = obj->min;
    p1->data = x;
    p1->next = obj;
    obj = p1;
    }

    void minStackPop(MinStack* obj) {
    obj = obj->next;
    }

    int minStackTop(MinStack* obj) {
    return obj->data;
    }

    int minStackGetMin(MinStack* obj) {
    return obj->min;
    }

    void minStackFree(MinStack* obj) {
    obj = NULL;
    }

    /**

    • Your MinStack struct will be instantiated and called as such:
    • struct MinStack* obj = minStackCreate(maxSize);
    • minStackPush(obj, x);
    • minStackPop(obj);
    • int param_3 = minStackTop(obj);
    • int param_4 = minStackGetMin(obj);
    • minStackFree(obj);
      */

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.