[prev] [index] [next]

A Linked List Implementation of a Quack (cont)

  • push(data,qs) makes another node
  • and populates it with data
  • the new node becomes the new top of quack qs (so the quack is a stack)

void push(int data, Quack qs) {
	if (qs == NULL) {
		fprintf(stderr, "push: quack not initialised\n");
	} else {
		Quack newnode = (Quack)malloc(sizeof(struct _node));
		assert(newnode != NULL);
		newnode->data = data;
		newnode->next = qs->next;   // old top
		qs->next = newnode;         // new top
	}
}