#include "StdAfx.h"
#include "QueueX.h"

QueueX::QueueX(int size)
{
	maxSize = size;
	que = new double[maxSize];
	front = 0;
	rear = -1;
	nItems = 0;
}

QueueX::~QueueX(void)
{
	delete []que;
}

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

double QueueX::remove()
{
	if(!isEmpty())
	{
		nItems--;
		int temp = front;
		circle(front);
		return que[temp];
	}
}

double QueueX::peekFront()
{
	if(!isEmpty())
	{
		return que[front];
	}
}

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++;
}