// Program Name:  Process Scheduler
// Programmer: Mark Dehus, 42
// Assignment Number: Project #1
// Purpose: To simulate and show the process scheduling
//			system of an operating system.

// Tested and compiled on Minigw (GCC 3.2) with Dev-C++ 4.9.8.0
// there is a couple problems on VC++ because it is outdated
// and no longer meets current ISO C++ - go and update your compiler.

#include <iostream>
#include "queue.h"

using namespace std;

queue::queue(int s)
{
	queueArray = new int[s];
	queueSize = s;
	front = 0;
	rear = 0;
	numItems = 0;

	for (int i = 0; i < s; i++)
		queueArray[i] = -1;
}

queue::~queue()
{
	delete [] queueArray;
}

void queue::enqueue(int num)
{
	if (isFull())
		cout << "The queue is full.\n";
	else{
		// Calc the new rear pos
  		rear = (rear + 1) % queueSize;
		// put in a new item
		queueArray[rear] = num;
		// update item count
		numItems++;
    }
}

int queue::dequeue()
{
	if (isEmpty())
		cout << "The queue is empty.\n";
	else
	{
		// Send to front
		front = (front + 1) % queueSize;
		// Update item count
		numItems--;
		return queueArray[front];
	}

	return -1;
}

bool queue::isEmpty()
{
	bool status;
	
	if (numItems)
		status = false;
	else
		status = true;
		
	return status;
}

bool queue::isFull()
{
	bool status;
	
	if (numItems < queueSize)
		status = false;
	else
		status = true;

	return status;
}

void queue::clear()
{
	front = queueSize - 1;
	rear = queueSize -1;
	numItems = 0;
}
