
package code.template;

/**
 *
 * @author 
 */
public class QueueArray {

    int QUEUE_SIZE;
    int front;
    int back;

    Integer[] queueArray;

    public QueueArray(int size) {
        queueArray = new Integer[size];
        QUEUE_SIZE = size;
    }


    public void equeue(int putInBackArray) {

        if (isFull()) {
            System.out.println("Sorry the quere is full");
        } else if (isEmpty()) {
            front = 0;
            back = 0;
        } else {
            back = (back + 1) % QUEUE_SIZE;
        }
        queueArray[back] = putInBackArray;

    }

    public int dequeue() {

        if (isEmpty()) {
            System.out.println("The queue is empty");
        } else if (front == back) {
            front = back - 1;

        } else {
            back = back + 1 % QUEUE_SIZE;
        }
        return queueArray[front];

    }

    public boolean isEmpty() {
        if (front == -1 && back == -1) {
            return true;
        } else {
            return false;
        }
    }

    public boolean isFull() {

        if ((back + 1) % QUEUE_SIZE == front) {
            return true;
        } else {
            return false;
        }
    }

    public int size() {

        return front;
    }

    public void print() {

        for (int i = 0; i < queueArray.length; i++) {
            System.out.println(i+"/t" + queueArray[i]);
        }
    }

}
