package LinkedLists; class CustomerQueue { // queue size static final int MAXSIZE = 10; // number of elements in default queue // pointers to front and rear private CustomerNode front; private CustomerNode rear; // size of queue and variable for max elements private int size; private int max; /** * default constructor */ public CustomerQueue() { front = null; rear = null; size = 0; max = MAXSIZE; } /** * Constructor for queue of size s */ public CustomerQueue(int s) { front = null; rear = null; size = 0; max = s; } /** * This method removes a customer from the front of the queue */ public CustomerNode dequeue() throws QueueEmptyException { CustomerNode temp; if (!isEmpty()) { temp = front; front = front.getNext(); size--; return temp; } else { throw new QueueEmptyException("nobody is in the queue"); } } /** * This method adds a customer to the rear of the queue */ public void enqueue(CustomerNode cn) throws QueueFullException { if (!isFull()) { if (isEmpty()) { newQueue(cn); } else { rear.setNext(cn); rear = cn; size++; } } else { throw new QueueFullException("Out of space in queue"); } } /** * This method was created in VisualAge. */ public CustomerNode getFront() { return front; } /** * This method was created in VisualAge. */ public CustomerNode getNext(CustomerNode n) { if (n != null) { return n.getNext(); } return null; } /** * This method was created in VisualAge. */ public CustomerNode getRear() { return rear; } /** * This method was created in VisualAge. * @return int */ public int getSize() { return size; } /** * This method was created in VisualAge. * @return boolean */ public boolean isEmpty() { if (size == 0) { return true; } return false; } /** * This method was created in VisualAge. * @return boolean */ public boolean isFull() { if (size == max) { return true; } return false; } /** * This method initialises a queue * @param cn LinkedLists.CustomerNode */ public void newQueue(CustomerNode cn) { front = cn; rear = cn; size = 1; } }