diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/exceptions/EmpyQueueException.java b/exceptions/EmpyQueueException.java new file mode 100644 index 0000000..ce3c20f --- /dev/null +++ b/exceptions/EmpyQueueException.java @@ -0,0 +1,14 @@ +package exceptions; + +/** + * Created with MONSTER. + * User: xgiovio + * Date: 05/03/14 + * Time: 0.09 + */ +public class EmpyQueueException extends RuntimeException { + + public EmpyQueueException(){ + super("Queue Empty"); + } +} diff --git a/queue/DynamicArrayQueue.java b/queue/DynamicArrayQueue.java new file mode 100644 index 0000000..94b325f --- /dev/null +++ b/queue/DynamicArrayQueue.java @@ -0,0 +1,99 @@ +package queue; + +import exceptions.EmpyQueueException; +import exceptions.EmpyStackException; + +/** + * Created with xgiovio.macbookair. + * User: xgiovio + * Date: 10/03/14 + * Time: 15:49 + */ +public class DynamicArrayQueue extends QueueRules { + + public DynamicArrayQueue(){ + queue = (E[])new Object[def_size]; + } + + public DynamicArrayQueue(int in_size){ + queue = (E[])new Object[in_size]; + } + + + @Override + public void enqueue(E element) { + if (front == -1){ + front++; + } + queue[rear]= element; + rear = (rear + 1) % queue.length; + if ( rear == front ){ + //reallocate; + E[] new_queue = (E[]) new Object[queue.length * 2]; + for (int i= 0 ;i { + + abstract public void enqueue (E element); + abstract public E dequeue () throws EmpyQueueException; + abstract public E front() throws EmpyQueueException; + abstract public boolean isEmpty(); + abstract public int size(); + +}