/* fifo.c - ownership of the nodes of the fifo is outside the fifo.
 *          implementing only put and get
 */

#include "fifo.h"
#include <stdlib.h>


/* adds an element to the queue. */
void put (fifo_t *fifop, node * new_node)
{
	node * p = new_node;

	p->next_ptr = NULL;
	if (fifop->front == NULL){
		fifop->front = p;
	} else {
		fifop->rear->next_ptr = p;
	}
	fifop->rear = p;
}


/* removes and returns an element from the queue. */
node * get (fifo_t *fifop)
{
	node *removep;	/* pointer to node being removed. */

	removep = fifop->front;
	if (removep) {
		fifop->front = removep->next_ptr;
		if(fifop->front == NULL)
			fifop->rear = NULL;
	}
	return removep;
}


