Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Really you are not modifying stack. You must to use &amp;stack for push, pop and empty methods. They will have following signature:</p> <pre><code>void push(Stack * stack, int type, void* value); void pop(Stack * stack, Node* node); void empty(Stack *stack); </code></pre> <p>and, of course, use pointer contents inside these methods, like:</p> <pre><code>void push(Stack * stack, int type, void* value) { int length; Node* node = (Node*) malloc(sizeof(Node)); node-&gt;index = (*stack)-&gt;index + 1; node-&gt;type = type; switch(node-&gt;type) { case INT: node-&gt;value.i = *((int*) value); break; case CHAR: node-&gt;value.c = *((char*) value); break; case STRING: length = strlen((char*) value) + 1; node-&gt;value.s = (char*) malloc(length * sizeof(char)); strcpy(node-&gt;value.s, value); break; } node-&gt;prev = *stack; *stack = node; } void pop(Stack * stack, Node* node) { int length; Node* temp = *stack; if (!isempty(*stack)) { node-&gt;index = (*stack)-&gt;index; node-&gt;type = (*stack)-&gt;type; switch((*stack)-&gt;type) { case INT: node-&gt;value.i = (*stack)-&gt;value.i; break; case CHAR: node-&gt;value.c = (*stack)-&gt;value.c; break; case STRING: length = strlen((*stack)-&gt;value.s) + 1; node-&gt;value.s = (char*) malloc(length * sizeof(char)); strcpy(node-&gt;value.s, (*stack)-&gt;value.s); free((*stack)-&gt;value.s); break; } node-&gt;prev = 0; *stack = (*stack)-&gt;prev; free(temp); } else { /*TODO: handle empty case */ puts("Stack empty!"); } } void empty(Stack *stack) { while (!isempty(*stack)) { Node* temp = malloc(sizeof(Node)); pop(stack, temp); free(temp); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload