function pop is done

This commit is contained in:
regis37 2025-11-26 22:56:13 +01:00
parent 69f44a5aa0
commit 5deaf21a61

12
stack.c
View File

@ -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.