prototype:
Code:
struct stack pop (struct stack ** tos);
In main:
Code:
if (tos == NULL)
{
printf ("stack empty!\n");
}else
{
struct stack temp = pop(&tos);
printf("%d popped.\n", temp.sdata);
}
function definition:
Code:
struct stack pop (struct stack ** tos)
{
//holds the return value (data)
struct stack temp;
//use to free the head node
struct stack **freep = tos;
//reposition the head of the stack for post pop
if((*tos)->next != NULL) *tos = (*tos)->next;
//get data value
temp = **freep;
//free head node
free(*freep);
return temp;
}
Where did I go wrong with this? I can't quite figure it.