[prev] [index] [next]

Implementing Quack Functions for Queues (cont)

qush(data,qs) in the Linked List Implementation
  • makes another node
  • and populates it with data
  • the new node becomes the new bottom of quack qs (so the quack is a queue)

void qush(int data, Quack que) {
	if (que == NULL) {
		fprintf(stderr, "qush: quack not initialised\n");
	} else {
		Quack newnode = (Quack)malloc(sizeof(struct _node));
		assert(newnode != NULL);
		newnode->data = data;
		newnode->next = NULL;    // will become the new bottom
		Quack endnode = que;
		while (endnode->next != NULL) {   // go to end of list
			endnode = endnode->next;
		}
		endnode->next = newnode;         // new bottom
	}
}