Question: Modify the code so that each teller has a separate queue. When customers arrive, they enter the shortest queue (and stay in that one, never


Modify the code so that each teller has a separate queue. When customers arrive, they enter the shortest queue (and stay in that one, never switching queues). Run both versions of the algorithm for an identical set of 100 customers with the same arrival and transaction times. Compare the average wait time for the two methods. Which seems to be better?

The code:

public class CircularQueue { private final int DEFCAP = 100; // default capacity private T[] queue; // array that holds queue elements private int numElements; // number of elements in this queue private int front; // index of front of queue private int rear; // index of rear of queue /** * Parameterized constructor which take size for initializing queue * @param maxSize */ public CircularQueue(int maxSize) { queue = (T[]) new Object[maxSize]; //setting front and back to same at starting front = 0; rear = 0; } /** * This constructor initializes the queue with default capacity */ public CircularQueue() { queue = (T[]) new Object[DEFCAP]; //setting front and back to same at starting front = 0; rear = 0; } /** * This method add element in queue */ public void enqueue(T element){ //Check if size is same as max capacity of queue if yes then give error Message if(numElements == queue.length) { System.out.println(\"Queue is full can't add more elements.\"); return; } //incrementing the size numElements++; //inserting element at rear queue[rear] = element; //incrementing rear position rear = (rear+1) % queue.length; } /** * This method remove element from queue */ public T dequeue() { //If size is 0 then print the message if(numElements == 0) { System.out.println(\"Queue is empty.\"); return null; } //getting element in front before remove T data = queue[front]; //Setting front element to null queue[front] = null; //setting front to next element in queue front = (front+1) % queue.length; //decrementing size of the queue on remove numElements--; return data; } /** * This method will check if queue is full or not, if full return true otherwise false */ public boolean isFull() { return (numElements == queue.length); } /** * This method return true if queue is empty otherwise false */ public boolean isEmpty() { return (numElements == 0); } /** * This method returns number of elements present in queue */ public int size() { return numElements; } /** * This method will return front element from queue * @return */ public T front() { return queue[front]; }}




Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!