[prev] [index] [next]

A Linked List Implementation of a Quack (cont)

  • pop(qs) checks if the quack qs is not empty
  • if so, retrieves the data of the top node
    • and the node is freed

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;
}