int pop(Quack qs) {
int retval = 0;
if (qs == NULL) {
fprintf(stderr, "pop: quack not initialised\n");
} else if (isEmptyQuack(qs)) {
fprintf(stderr, "pop: quack underflow\n");
} else {
Quack topnode = qs->next; // top node must be there
retval = topnode->data;
qs->next = topnode->next; // new top
free(topnode); // free the old top
}
return retval;
}
|