Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include struct Queue // circular queue struct { int size; int front; int rear; int*time_arr; }; int isEmpty(struct Queue *q)// function to check
#include
#include
#include
struct Queue // circular queue struct
{
int size;
int front;
int rear;
int*time_arr;
};
int isEmpty(struct Queue *q)// function to check is queue is empty
{
if (q->rear == q->front)
{
return 1;
}
return 0;
}
void enqueue(struct Queue *q, int time) //function to enqueue elements into the queue
{
q->rear = (q->rear + 1)% q->size;
q->time_arr[q->rear] = time;
}
int dequeue(struct Queue *q) // function to dequeue elements from queue
{
int a = -1;
q->front = (q->front + 1)% q->size;
a = q->time_arr[q->front];
}
int main ()
{
// creating queue instances for jobs of type A and jobs of type B
struct Queue job_A;
struct Queue job_B;
//fixing size of queue as 10, although user can change as per requirement
job_A.size = 10;
job_B.size = 10;
//setting front and rear position of queue
job_A.front = job_A.rear = 0;
job_B.rear = 0;
job_B.front = 0;
//dynamically allocating the queue array space
job_A.time_arr =
(int *)malloc(job_A.size*sizeof(int));
job_B.time_arr =
(int *)malloc(job_B.size*sizeof(int));
printf ("Enter total number of user to apply the job : ");
int n;
scanf("%d", &n);
float TOTAL = 0;
for (int i=0; i <>
Task 2: Complexity Analysis - Theoretically discuss and compute the complexity of all algorithms that you implemented. The discussion will describe your understanding of the algorithm. Define the complexity of the algorithm by using Big 'O' notation {
printf("Select the type of job you applied : 1.job_A 2.job_B ");
int x;
scanf("%d", &x);
int random;
if (x == 1)
{
random = rand() % 10;
enqueue(&job_A,random);
printf("Your expected waiting time is %dS. Thankyou for your patience. ", random);
TOTAL = TOTAL + random;
}
if (x == 2)
{
random = rand() % 10;
enqueue(&job_B,random);
printf("Your expected waiting time is %ds. Thankyou for your patience. ", random);
TOTAL = TOTAL + random;
}
}
float Average = TOTAL;
printf(" ");
while (isEmpty(&job_B)==0)
{
printf("job B with time expected %ds is served. ", dequeue (&job_B));
}
while (isEmpty(&job_A)==0)
{
printf("job A with time expected %dS is served. ",dequeue(&job_A));
}
printf("Average of time expected is %f", Average);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started