// fifo.cpp  -- A queue of integers (dynamic storage)

#include <stdlib.h>  // Defines NULL as 0L
#include "fifo.h"

// Constructor
Fifo::Fifo()
{
	head = NULL;
	tail = NULL;
}

// enqueue a new value
void Fifo::enqueue(int who)
{
	node *a = new node;

	a->next = NULL;
	a->value = who;
	if (head == NULL)
		head = a;
	else
		tail->next = a;
	tail = a;
}

// dequeue a value from a fifo
int Fifo::dequeue()
{
	node *headNode;
	int who;

	if (head != NULL) {
		headNode = head;
		head = head->next;
		who = headNode->value;
		if (head == NULL)
			tail = NULL;
		delete headNode;
		return who;
	}
	return 0; // You should never execute this
	          // statement (i.e. do not dequeue
			  // from an empty queue)
}

// check if a fifo is empty
int Fifo::isempty()
{
	return (head == NULL);
}