#include "StdAfx.h"
#include "queuex.h"

queuex::queuex(int s)
{
	maxSize = s;
	arr = new double[maxSize];
	front = 0;
	rear = -1;
	nItems = 0;
}

queuex::~queuex(void)
{
	delete []arr;
}

void queuex::insert(double d)
{
	if(! isFull())
	{
		circle(rear);
		arr[rear] = d;
		nItems++;
	}
}

double queuex::remove()
{
	if(! isEmpty())
	{
		nItems--;
		int temp = front;
		circle(front);
		return arr[temp];
	}
	else
		return -999;
}

double queuex::peekFront()
{
	if(! isEmpty())
		return arr[front];
	else
		return -998;
}

int queuex::size()
{
	return nItems;
}

bool queuex::isEmpty()
{
	return (nItems==0);
}

bool queuex::isFull()
{
	return (nItems==maxSize);
}

void queuex::circle(int &pos)
{
	if (pos==maxSize-1)
		pos=0;
	else
		pos++;
}