@@ -0,0 +1,2162 @@
+/*%0A * A queue data structure functions the same as a real world queue.%0A * The elements that are added first are the first to be removed.%0A * New elements are added to the back/rear of the queue. %0A */%0Aclass Queue%7B%0A%09private int maxSize;%0A%09private int%5B%5D queueArray;%0A%09private int front;%0A%09private int rear;%0A%09private int nItems;%0A%09%0A%09public Queue(int size)%7B //Constructor%0A%09%09maxSize = size;%0A%09%09queueArray = new int%5Bsize%5D;%0A%09%09front = 0;%0A%09%09rear = -1;%0A%09%09nItems = 0;%0A%09%7D%0A%09%0A%09public boolean insert(int x)%7B //Inserts an element at the rear of the queue%0A%09%09if(isFull())%0A%09%09%09return false;%0A%09%09if(rear == maxSize-1) //If the back of the queue is the end of the array wrap around to the front%0A%09%09%09rear = -1;%0A%09%09rear++;%0A%09%09queueArray%5Brear%5D = x;%0A%09%09nItems++;%0A%09%09return true;%0A%09%7D%0A%09%0A%09public int remove()%7B //Remove an element from the front of the queue%0A%09%09if(isEmpty())%7B%0A%09%09%09System.out.println(%22Queue is empty%22);%0A%09%09%09return -1;%0A%09%09%7D%09%0A%09%09int temp = queueArray%5Bfront%5D;%0A%09%09front++;%0A%09%09if(front == maxSize) //Dealing with wrap-around again%0A%09%09%09front = 0;%0A%09%09nItems--;%0A%09%09return temp;%0A%09%7D%0A%09%0A%09public int peekFront()%7B //Checks what's at the front of the queue%0A%09%09return queueArray%5Bfront%5D;%0A%09%7D%0A%09%0A%09public int peekRear()%7B //Checks what's at the rear of the queue%0A%09%09return queueArray%5Brear%5D;%0A%09%7D%0A%09%0A%09public boolean isEmpty()%7B //Returns true is the queue is empty%0A%09%09return(nItems == 0);%0A%09%7D%0A%09%0A%09public boolean isFull()%7B //Returns true is the queue is full%0A%09%09return(nItems == maxSize);%0A%09%7D%0A%09%0A%09public int getSize()%7B //Returns the number of elements in the queue%0A%09%09return nItems;%0A%09%7D%0A%7D%0A//Example%0Apublic class Queues%7B%0A%09public static void main(String args%5B%5D)%7B%0A%09%09Queue myQueue = new Queue(4);%0A%09%09myQueue.insert(10);%0A%09%09myQueue.insert(2);%0A%09%09myQueue.insert(5);%0A%09%09myQueue.insert(3);%0A%09%09//%5B10(front), 2, 5, 3(rear)%5D%0A%09%09%0A%09%09System.out.println(myQueue.isFull()); //Will print true%0A%09%09%0A%09%09myQueue.remove(); //Will make 2 the new front, making 10 no longer part of the queue%0A%09%09//%5B10, 2(front), 5, 3(rear)%5D%0A%09%09%0A%09%09myQueue.insert(7); //Insert 7 at the rear which will be index 0 because of wrap around%0A%09%09// %5B7(rear), 2(front), 5, 3%5D%0A%09%09%0A%09%09System.out.println(myQueue.peekFront()); //Will print 2%0A%09%09System.out.println(myQueue.peekRear()); //Will print 7 %09%0A%09%7D%0A%7D%0A

Create Queues.java