Use the Average Waiting Time program to determine a reasonable number of queues
ID: 3803964 • Letter: U
Question
Use the Average Waiting Time program to determine a reasonable number of queues to use if there are 1000 customers and:
a) The inner-arrival time is 5 and the service time is 5
b) The inner-arrival time is 1 and the service time is 5
c) The inner-arrival time ranges from 0 to 20, and the service time ranges from 20 to 100
d) The inner-arrival time ranges from 0 to 2, and the service time ranges from 20 to 100
In each case, descripe how you arrived at your result
//---------------------------------------------------------------------------
// ArrayUnbndQueue.java by Dale/Joyce/Weems Chapter 5
//
// Implements UnboundedQueueInterface with an array to hold queue elements.
//
// Two constructors are provided; one that creates a queue of a default
// original capacity and one that allows the calling program to specify the
// original capacity.
//
// If an enqueue is attempted when there is no room available in the array, a
// new array is created, with capacity incremented by the original capacity.
//---------------------------------------------------------------------------
package ch05.queues;
public class ArrayUnbndQueue<T> implements UnboundedQueueInterface<T>
{
protected final int DEFCAP = 100; // default capacity
protected T[] queue; // array that holds queue elements
protected int origCap; // original capacity
protected int numElements = 0; // number of elements in the queue
protected int front = 0; // index of front of queue
protected int rear; // index of rear of queue
public ArrayUnbndQueue()
{
queue = (T[]) new Object[DEFCAP];
rear = DEFCAP - 1;
origCap = DEFCAP;
}
public ArrayUnbndQueue(int origCap)
{
queue = (T[]) new Object[origCap];
rear = origCap - 1;
this.origCap = origCap;
}
private void enlarge()
// Increments the capacity of the queue by an amount
// equal to the original capacity.
{
// create the larger array
T[] larger = (T[]) new Object[queue.length + origCap];
// copy the contents from the smaller array into the larger array
int currSmaller = front;
for (int currLarger = 0; currLarger < numElements; currLarger++)
{
larger[currLarger] = queue[currSmaller];
currSmaller = (currSmaller + 1) % queue.length;
}
// update instance variables
queue = larger;
front = 0;
rear = numElements - 1;
}
public void enqueue(T element)
// Adds element to the rear of this queue.
{
if (numElements == queue.length)
enlarge();
rear = (rear + 1) % queue.length;
queue[rear] = element;
numElements = numElements + 1;
}
public T dequeue()
// Throws QueueUnderflowException if this queue is empty;
// otherwise, removes front element from this queue and returns it.
{
if (isEmpty())
throw new QueueUnderflowException("Dequeue attempted on empty queue.");
else
{
T toReturn = queue[front];
queue[front] = null;
front = (front + 1) % queue.length;
numElements = numElements - 1;
return toReturn;
}
}
public boolean isEmpty()
// Returns true if this queue is empty; otherwise, returns false
{
return (numElements == 0);
}
}
//----------------------------------------------------------------------------
// UnboundedQueueInterface.java by Dale/Joyce/Weems Chapter 5
//
// Interface for a class that implements a queue of T with no bound
// on the size of the queue. A queue is a "first in, first out" structure.
//----------------------------------------------------------------------------
package ch05.queues;
public interface UnboundedQueueInterface<T> extends QueueInterface<T>
{
void enqueue(T element);
// Adds element to the rear of this queue.
}
//----------------------------------------------------------------------------
// QueueInterface.java by Dale/Joyce/Weems Chapter 5
//
// Interface for a class that implements a queue of T.
// A queue is a "first in, first out" structure.
//----------------------------------------------------------------------------
package ch05.queues;
public interface QueueInterface<T>
{
T dequeue() throws QueueUnderflowException;
// Throws QueueUnderflowException if this queue is empty;
// otherwise, removes front element from this queue and returns it.
boolean isEmpty();
// Returns true if this queue is empty; otherwise, returns false.
}
AWT model
public class GlassQueue<T> extends ArrayUnbndQueue<T>
public class ArrayUnbndQueue<T> implements UnboundedQueueInterface<T>
public interface UnboundedQueueInterface<T> extends QueueInterface<T>
{
void enqueue(T element);
//Adds element to the rear of this quee.
}
public interface QueueInterface<T>
{
T dequeue() throws QueueUnderflowException;
//Throws QueueUnderflowException if this queue is empty;
//otherwise, removes front element from this queue and returns it
boolean isEmpty();
//Returns true if this queue is empty; otherwise, return false
}
Explanation / Answer
Answer:
#include<iostream>
using namespace std;
struct node
{
int info;
node *later;
}*front_end = NULL,*rear_end = NULL,*p = NULL,*node_pointer = NULL;
void push(int value)
{
node_pointer = new node;
node_pointer->info = value;
node_pointer->later = NULL;
if(front_end == NULL)
{
front_end = rear_end = node_pointer;
rear_end->later = NULL;
}
else
{
rear_end->later = node_pointer;
rear_end = node_pointer;
rear_end->later = NULL;
}
}
int remove()
{
int value;
if(front_end == NULL)
{
cout<<" queue is empty ";
}
else
{
p = front_end;
value = p->info;
front_end = front_end->later;
delete(p);
return(value);
}
}
int main()
{
int n,c = 0,value;
cout<<"Enter the number of values to be pushed into queue ";
cin>>n;
while (c < n)
{
cout<<"Enter the value to be entered into queue ";
cin>>value;
push(value);
c++;
}
cout<<" Deleted Values ";
while(true)
{
if (front_end != NULL)
cout<<remove()<<endl;
else
break;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.