Queue Implementation

The queue is defined type of linear data structure, in which the elements are stored in ordered sequence. The most important operations are the adding of an element at the back end of the sequence (enqueue) and the extraction of the element from the front end of the sequence (dequeue). The queue is an example for the First-In-First-Out(FIFO) data structure types. The first element that is enqueued will be also the first that is taken from the queue.

There could be made an analogy between the practical meaning of the word queue. For example, lets take an queue from people waiting at front of a kiosk to buy a ticket. Then we should order at the rear and to wait our turn. That is when we go to the front of the queue and there is nobody before us (if there was someone, then he had been served already). Then we could be served and to leave the queue.

Here is my implementation of queue:

/**
 * This class implements a half-static queue
 * @author Hristo Georgiev
 */

public class xQueue<T> {
    private final int INITIAL_ARRAY_LENGTH = 4;
    private final int INITIAL_POSITION = 0;
    private int size;
    private int count;
    private int position;

    private T[] queue;
       
    /**
    * Constructor of empty queue
    */

    public xQueue(){
        this.count = -1;
        this.size = INITIAL_ARRAY_LENGTH;
        this.position = INITIAL_POSITION;
        this.queue = (T[])new Object[this.size];
    }
   
    /**
    * Enqueue an element to the queue
    */

    public void enqueue(T element){
        this.count++;
        if(this.count >= this.size){
            this.resizeArray();
        }
        queue[this.count] = element;
    }

    /**
    * Dequeue an element to the queue
    */

    public T dequeue(){
        if(!isEmpty()){
            return this.queue[position++];
        }else{
            return null;
        }
    }

    /**
    * Checks if the queue is empty
    */

    public boolean isEmpty(){
        if(this.position == this.size){
            return true;
        }
        return false;
    }
   
    private void resizeArray(){
        T[] newQueue = (T[])new Object[2*this.size];
        System.arraycopy(this.queue, 0, newQueue, 0, this.size);
        this.queue = newQueue;
        this.size *= 2;
    }
}