package com.study.arithmetic;
public class Queue<E> {
private Object[] elements;
private int head = 0;
private int tail = 0;
private int size = 0;
public Queue() {
elements = new Object[3];
}
public Queue(int size) {
if(size <= 0)
size = 10;
elements = new Object[size];
}
public boolean enQueue(E e) {
if(size >= elements.length)
return false;
elements[tail] = e;
if(tail == elements.length-1)
tail = 0;
else
tail++;
size++;
return true;
}
@SuppressWarnings("unchecked")
public E deQueue() {
if(size == 0)
return null;
E ret = (E) elements[head];
if(head == elements.length-1)
head = 0;
else
head++;
size--;
return ret;
}
public int size() {
return size;
}
}