function pop is done
This commit is contained in:
parent
69f44a5aa0
commit
5deaf21a61
10
stack.c
10
stack.c
@ -22,7 +22,12 @@ return newNode;
|
|||||||
// freed by caller.)
|
// freed by caller.)
|
||||||
StackNode *pop(StackNode *stack)
|
StackNode *pop(StackNode *stack)
|
||||||
{
|
{
|
||||||
|
if (stack == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
StackNode *next = stack->next;
|
||||||
|
free(stack);
|
||||||
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the data of the top element.
|
// Returns the data of the top element.
|
||||||
@ -30,10 +35,7 @@ void *top(StackNode *stack)
|
|||||||
{
|
{
|
||||||
if (stack == NULL)
|
if (stack == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
return stack->data;
|
||||||
StackNode *next = stack->next;
|
|
||||||
free(stack);
|
|
||||||
return next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clears stack and releases all memory.
|
// Clears stack and releases all memory.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user