diff --git a/stack.c b/stack.c index 232a2b6..016ff5b 100644 --- a/stack.c +++ b/stack.c @@ -22,18 +22,20 @@ return newNode; // freed by caller.) StackNode *pop(StackNode *stack) { + if (stack == NULL) + return NULL; + StackNode *next = stack->next; + free(stack); + return next; } // Returns the data of the top element. void *top(StackNode *stack) { if (stack == NULL) - return NULL; - -StackNode *next = stack->next; -free(stack); -return next; + return NULL; +return stack->data; } // Clears stack and releases all memory.