Please review the code:
package com.gmail.practice;
import java.util.Arrays;
public class Queues {
int head;
int tail;
int size;
int[] queue;
public Queues(int arraysize)
{
if(arraysize<0)
{
throw new IllegalArgumentException("size cannote be less than equals zero");
}
head = -1;
tail = -1;
size = arraysize;
queue = new int[size];
}
public boolean isEmpty()
{
return(tail == -1 && head == -1);
}
public void enqueue(int value)
{
if((tail+1)%size == head)
{
System.out.println("the queue is full");
}else if(isEmpty())
{
head++;
tail++;
queue[tail] = value;
}else{
tail = (tail+1)%size;
queue[tail] = value;
}
}
public int dequeue()
{
int value = 0;
if(isEmpty())
{
System.out.println("the queue is empty cant dequeue");
}else if(tail == head){
value = queue[head];
head = -1;
tail = -1;
}else{
value = queue[head];
head = (head+1)%size;
}
return value;
}
public void display()
{
System.out.println(Arrays.toString(queue) + " " + "tail is " + " "+ tail +" the head is" + " " + head);
}
public static void main(String[] args)
{
Queues q = new Queues(5);
q.enqueue(3);
q.enqueue(4);
q.enqueue(2);
q.enqueue(1);
q.enqueue(5);
q.display();
q.dequeue();
q.dequeue();
q.display();
q.enqueue(1);
q.enqueue(5);
q.dequeue();
q.dequeue();
}
}