package DataStructures;

public class Queue {

	private int[] data;  // array to store queue elements
	private int front;   // front points to the front element in the queue
	private int rear;    // rear points to the last element in the queue
	private int max;     // maximum capacity of the queue
    private int count;   // current size of the queue

	public Queue(int maxSize) {
		data = new int[maxSize];
		max = maxSize;
		front = -1;
		rear = -1;
		count = 0;

	}
	

	// removing the front element
	public String dequeue() {

		// check if queue empty
		if (isEmpty()) {
			return ("No items in the queue, cannot delete");
		}
		// adjust new size of array
		front = (front + 1) % size();
		count --;
		return ("Deleting " + data[front]);

	}
	// enqueue value from rear
	public String enqueue(int val) {
		//if queue is empty, then check if 
		if (isFull()) {
			return ("Queue full! Cannot add more values");

		}

		rear = (rear + 1) % max;
		data[rear] = val;
		count++;

		return ("Adding " + val);
	}
	// return front element of queue
	public int peek()
	{
		return data[front];
	}

	// check if the queue is empty or not
	public Boolean isEmpty() {
		return (size() == 0);
	}

	// check if the queue is full or not
	public Boolean isFull() {
		return (size() == max);
	}

	// returns the size of the queue
	public int size() {
		return count;
	}
	// public String toString(){

	// 	for (int i = 0; i <= front; i++) {
	// 		System.out.println(data[0]);
	// 	}
	// 	return "";
	// }

}